public bool AddGame(GameViewModel model) { using (var db = new GameStoreDbContext()) { if (db.Games.Any(g => g.Title == model.Title)) { return(false); } var game = new Game { Title = model.Title, Desctription = model.Desctription, Price = model.Price, ReleaseDate = model.ReleaseDate, Size = model.Size, ThumbnailURL = model.ThumbnailURL, TrailerId = model.TrailerId }; db.Add(game); db.SaveChanges(); return(true); } }
public bool Create(string email, string password, string name) { using (var db = new GameStoreDbContext()) { if (db.Users.Any(u => u.Email == email)) { return(false); } var isAdmin = !db.Users.Any(); var user = new User { Email = email, Name = name, Password = password, IsAdmin = isAdmin }; db.Add(user); db.SaveChanges(); return(true); } }
public void Create( string title, string description, string image, decimal price, double size, string videoId, DateTime releaseDate) { using (var db = new GameStoreDbContext()) { var game = new Game { Title = title, Description = description, Image = image, Price = price, Size = size, VideoId = videoId, ReleaseDate = releaseDate }; db.Add(game); db.SaveChanges(); } }
public bool Create(string email, string name, string password) { using (var context = new GameStoreDbContext()) { // Ensure Unique Email var emailExists = context.Users.Any(u => u.Email == email); if (emailExists) { return(false); } // The first registered user is admin var isAdmin = !context.Users.Any(); // Create User var user = new User { Email = email, Name = name, Password = password, IsAdmin = isAdmin }; context.Add(user); context.SaveChanges(); return(true); } }
public int Order(HashSet <IndexViewGame> orderGames, string username) { using (var db = new GameStoreDbContext()) { int userId = this.Find(username).Id; var user = db.Users .First(u => u.Id == userId); var userGames = db.UserGames.Where(ug => ug.UserId == userId); foreach (var orderGame in orderGames) { var game = db.Games .First(g => g.Id == orderGame.Id); var order = new UserGame() { UserId = user.Id, User = user, GameId = game.Id, Game = game }; if (!userGames.Any(ug => ug.UserId == userId && ug.GameId == game.Id)) { db.Add(order); } } return(db.SaveChanges()); } }
public bool Save(string email, string password, string fullName) { using (var db = new GameStoreDbContext()) { var users = db.Users; if (users.Any(u => u.Email.ToLower() == email.ToLower())) { return(false); } User user = new User() { Email = email, FullName = fullName, Password = password, IsAdmin = !users.Any() }; db.Add(user); db.SaveChanges(); return(true); } }
public void CreateOrder(int userId, IEnumerable <int> gameIds) { using (var db = new GameStoreDbContext()) { var order = new Order { UserId = userId, Games = gameIds.Select(id => new OrderGame() { GameId = id }).ToList() }; var user = db.Users.First(u => u.Id == userId); foreach (var id in gameIds) { user.Games.Add(new UserGame { GameId = id }); } order.TotalPrice = db.Games.Where(g => gameIds.Contains(g.Id)).Sum(g => g.Price); db.Add(order); db.SaveChanges(); } }
public bool Create(string email, string name, string password) { using (GameStoreDbContext db = new GameStoreDbContext()) { if (db.Users.Any(u => u.Email == email)) { // email must be unique return(false); } // the first registered becomes admin bool isAdmin = !db.Users.Any(); User user = new User { Email = email, Name = name, Password = password, IsAdmin = isAdmin }; db.Add(user); db.SaveChanges(); } return(true); }
public IActionResult Create(int id, string name, string dlc, double price, string platform) { Game game = new Game { Id = id, Name = name, Dlc = dlc, Price = price, Platform = platform }; using (var db = new GameStoreDbContext()) { db.Add(game); db.SaveChanges(); } return(RedirectToAction("Index")); }
public void Create(string title, string trailerId, string imageUrl, double size, decimal price, string description, DateTime releaseDate) { using (var db = new GameStoreDbContext()) { var game = new Game() { Title = title, TrailerId = trailerId, ImageThumbnail = imageUrl, Size = size, Price = price, Description = description, ReleaseDate = releaseDate }; db.Add(game); db.SaveChanges(); } }