-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a753252
commit ccff46d
Showing
36 changed files
with
3,534 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+162 KB
ExamPrep-01-September-2018/01. Model Definition_Problem Description.docx
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VaporStore", "VaporStore\VaporStore.csproj", "{ED12E334-BE70-4871-974E-392404F6FBE1}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Debug|x64.Build.0 = Debug|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Debug|x86.Build.0 = Debug|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Release|x64.ActiveCfg = Release|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Release|x64.Build.0 = Release|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Release|x86.ActiveCfg = Release|Any CPU | ||
{ED12E334-BE70-4871-974E-392404F6FBE1}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
19 changes: 19 additions & 0 deletions
19
ExamPrep-01-September-2018/VaporStore/Data/Attributes/AtLeastOneElementAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace VaporStore.Data.Attributes | ||
{ | ||
using System.Collections; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
public class AtLeastOneElementAttribute : ValidationAttribute | ||
{ | ||
public override bool IsValid(object value) | ||
{ | ||
IList collection = value as IList; | ||
if (collection != null) | ||
{ | ||
return collection.Count > 0; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace VaporStore.Data | ||
{ | ||
public static class Configuration | ||
{ | ||
public static string ConnectionString = | ||
@"Server=.;Database=VaporStore;Trusted_Connection=True"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace VaporStore.Data.Enums | ||
{ | ||
public enum CardType | ||
{ | ||
Debit, | ||
Credit | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
ExamPrep-01-September-2018/VaporStore/Data/Enums/PurchaseType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace VaporStore.Data.Enums | ||
{ | ||
public enum PurchaseType | ||
{ | ||
Retail, | ||
Digital | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace VaporStore.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using VaporStore.Data.Enums; | ||
|
||
public class Card | ||
{ | ||
[Key] | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
[RegularExpression(@"^[0-9]{4}\s*[0-9]{4}\s*[0-9]{4}\s*[0-9]{4}$")] | ||
public string Number { get; set; } | ||
|
||
[Required] | ||
[RegularExpression(@"^[0-9]{3}$")] | ||
public string Cvc { get; set; } | ||
|
||
[Required] | ||
public CardType Type { get; set; } | ||
|
||
[ForeignKey(nameof(User))] | ||
public int UserId { get; set; } | ||
[Required] | ||
public User User { get; set; } | ||
|
||
public ICollection<Purchase> Purchases { get; set; } = new HashSet<Purchase>(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
ExamPrep-01-September-2018/VaporStore/Data/Models/Developer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace VaporStore.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
public class Developer | ||
{ | ||
[Key] | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
public string Name { get; set; } | ||
|
||
public ICollection<Game> Games { get; set; } = new HashSet<Game>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace VaporStore.Data.Models | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using VaporStore.Data.Attributes; | ||
|
||
public class Game | ||
{ | ||
[Key] | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
public string Name { get; set; } | ||
|
||
[Required] | ||
[Range(typeof(decimal), "0", "79228162514264337593543950335")] | ||
public decimal Price { get; set; } | ||
|
||
[Required] | ||
public DateTime ReleaseDate { get; set; } | ||
|
||
[Required] | ||
[ForeignKey(nameof(Developer))] | ||
public int DeveloperId { get; set; } | ||
public Developer Developer { get; set; } | ||
|
||
[Required] | ||
[ForeignKey(nameof(Genre))] | ||
public int GenreId { get; set; } | ||
public Genre Genre { get; set; } | ||
|
||
public ICollection<Purchase> Purchases { get; set; } = new HashSet<Purchase>(); | ||
|
||
[AtLeastOneElement] | ||
public ICollection<GameTag> GameTags { get; set; } = new HashSet<GameTag>(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
ExamPrep-01-September-2018/VaporStore/Data/Models/GameTag.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace VaporStore.Data.Models | ||
{ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
public class GameTag | ||
{ | ||
public int GameId { get; set; } | ||
[Required] | ||
public Game Game { get; set; } | ||
|
||
public int TagId { get; set; } | ||
[Required] | ||
public Tag Tag { get; set; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
ExamPrep-01-September-2018/VaporStore/Data/Models/Genre.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace VaporStore.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
public class Genre | ||
{ | ||
[Key] | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
public string Name { get; set; } | ||
|
||
public ICollection<Game> Games { get; set; } = new HashSet<Game>(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
ExamPrep-01-September-2018/VaporStore/Data/Models/Purchase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace VaporStore.Data.Models | ||
{ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using VaporStore.Data.Enums; | ||
|
||
public class Purchase | ||
{ | ||
[Key] | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
public PurchaseType Type { get; set; } | ||
|
||
[Required] | ||
[RegularExpression(@"^[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$")] | ||
public string ProductKey { get; set; } | ||
|
||
[Required] | ||
public DateTime Date { get; set; } | ||
|
||
[ForeignKey(nameof(Card))] | ||
public int CardId { get; set; } | ||
[Required] | ||
public Card Card{ get; set; } | ||
|
||
[ForeignKey(nameof(Game))] | ||
public int GameId { get; set; } | ||
[Required] | ||
public Game Game { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace VaporStore.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
public class Tag | ||
{ | ||
[Key] | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
public string Name { get; set; } | ||
|
||
public ICollection<GameTag> GameTags { get; set; } = new HashSet<GameTag>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace VaporStore.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
public class User | ||
{ | ||
[Key] | ||
public int Id { get; set; } | ||
|
||
[MinLength(3), MaxLength(20)] | ||
[Required] | ||
public string Username { get; set; } | ||
|
||
[Required] | ||
[RegularExpression(@"^[A-Z]{1}[A-Za-z]* [A-Z]{1}[A-Za-z]*$")] | ||
public string FullName { get; set; } | ||
|
||
[Required] | ||
public string Email { get; set; } | ||
|
||
[Required] | ||
[Range(3, 103)] | ||
public int Age { get; set; } | ||
|
||
public ICollection<Card> Cards { get; set; } = new HashSet<Card>(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
ExamPrep-01-September-2018/VaporStore/Data/VaporStoreDbContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
namespace VaporStore.Data | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using VaporStore.Data.Models; | ||
|
||
public class VaporStoreDbContext : DbContext | ||
{ | ||
public VaporStoreDbContext() | ||
{ | ||
} | ||
|
||
public VaporStoreDbContext(DbContextOptions options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<Purchase> Purchases { get; set; } | ||
public DbSet<Card> Cards { get; set; } | ||
public DbSet<Game> Games { get; set; } | ||
public DbSet<GameTag> GameTags { get; set; } | ||
public DbSet<User> Users { get; set; } | ||
public DbSet<Tag> Tags { get; set; } | ||
public DbSet<Developer> Developers { get; set; } | ||
public DbSet<Genre> Genres { get; set; } | ||
|
||
protected override void OnConfiguring(DbContextOptionsBuilder options) | ||
{ | ||
if (!options.IsConfigured) | ||
{ | ||
options | ||
.UseSqlServer(Configuration.ConnectionString); | ||
} | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder model) | ||
{ | ||
model.Entity<GameTag>().HasKey(x => new { x.TagId, x.GameId }); | ||
|
||
model.Entity<GameTag>().HasOne(x => x.Game) | ||
.WithMany(g => g.GameTags) | ||
.HasForeignKey(x => x.GameId); | ||
|
||
model.Entity<GameTag>().HasOne(x => x.Tag) | ||
.WithMany(t => t.GameTags) | ||
.HasForeignKey(x => x.TagId); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
ExamPrep-01-September-2018/VaporStore/DataProcessor/Bonus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace VaporStore.DataProcessor | ||
{ | ||
using System.Linq; | ||
using Data; | ||
|
||
public static class Bonus | ||
{ | ||
public static string UpdateEmail(VaporStoreDbContext context, string username, string newEmail) | ||
{ | ||
var user = context.Users.FirstOrDefault(x => x.Username == username); | ||
if (user == null) | ||
{ | ||
return $"User {username} not found"; | ||
} | ||
|
||
var isTaken = context.Users.FirstOrDefault(x => x.Email == newEmail) != null; | ||
if (isTaken) | ||
{ | ||
return $"Email {newEmail} is already taken"; | ||
} | ||
|
||
user.Email = newEmail; | ||
|
||
context.SaveChanges(); | ||
|
||
return $"Changed {username}'s email successfully"; | ||
} | ||
} | ||
} |
Oops, something went wrong.