Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,CategoryName,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> Create([Bind("GameGenreId,Name")] GameGenre gameGenre)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gameGenre);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gameGenre));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("ID,Nombre,Direccion")] Tienda tienda)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tienda);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tienda));
        }
        public async Task <IActionResult> Create([Bind("ID,GameImage,Title,Genre,Price,Description,UnitsInStock")] Game game)
        {
            if (ModelState.IsValid)
            {
                _context.Add(game);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(game));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("ID,CreateDate,EmailAddress")] W_Email w_Email)
        {
            if (ModelState.IsValid)
            {
                _context.Add(w_Email);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(w_Email));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("Id,Name,ShortDescription,LongDescription,Image,Price,IsFavourite,Available,CategoryId")] Game game)
        {
            if (ModelState.IsValid)
            {
                _context.Add(game);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Id", game.CategoryId);
            return(View(game));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("ID,Nombre,Modelo,Descripcion,Cantidad,Precio,FechaSalida,Estado,Genero,TiendaId")] Juego juego)
        {
            if (ModelState.IsValid)
            {
                _context.Add(juego);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TiendaId"] = new SelectList(_context.Tienda, "ID", "Nombre", juego.TiendaId);
            return(View(juego));
        }
        public async Task <IActionResult> AddToCart(int id)
        {
            var gameToAdd   = _context.Game.SingleOrDefault(g => g.ID == id);
            var cartToAddTo = CartLogic.GetCart(_context, HttpContext);

            await cartToAddTo.AddToCart(gameToAdd);

            await _context.SaveChangesAsync();

            await cartToAddTo.SetCartTotal();

            return(RedirectToAction(nameof(ShowCarts)));
        }
Esempio n. 9
0
        public async Task <IActionResult> Create([Bind("ID,MarcaId,Modelo,Descripcion,Cantidad,Precio,FechaSalida,Estado,TiendaId")] Consola consola)
        {
            if (ModelState.IsValid)
            {
                _context.Add(consola);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MarcaId"]  = new SelectList(_context.Marca, "ID", "Nombre", consola.MarcaId);
            ViewData["TiendaId"] = new SelectList(_context.Tienda, "ID", "Nombre", consola.TiendaId);
            return(View(consola));
        }
Esempio n. 10
0
        public async Task <IActionResult> Create([Bind("OrderId,FirstName,LastName,IdentityNo,Address,PostalCode,City,Email,Phone,Total,OrderCreationDate")] Order order)
        {
            var cart = CartLogic.GetCart(_context, HttpContext);
            await cart.SetOrderIdNo(order);

            if (ModelState.IsValid)
            {
                _context.Add(order);
                HttpContext.Session.Clear();
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction(nameof(Details), order));
        }
Esempio n. 11
0
        public async Task <IActionResult> Create([Bind("CreditId,AccountId,CardTypeId,CardNumber,CardCode,ExpireDate,CardHolder,BillingAddress,BillingPhone,CountryId,ProvinceStateId")] CreditCard creditCard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(creditCard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AccountId"]       = new SelectList(_context.Account, "AccountId", "AspuserId", creditCard.AccountId);
            ViewData["CardTypeId"]      = new SelectList(_context.CardType, "CardTypeId", "CardType1", creditCard.CardTypeId);
            ViewData["CountryId"]       = new SelectList(_context.BillingCountry, "CountryId", "Name", creditCard.CountryId);
            ViewData["ProvinceStateId"] = new SelectList(_context.BillingProvinceState, "ProvinceStateId", "Name", creditCard.ProvinceStateId);
            return(View(creditCard));
        }
Esempio n. 12
0
        public async Task <Order> AddToOrderAsync(string accountId, int productId)
        {
            var tempOrder = await CreateOrderAsync(accountId);

            var newOrderProducts = new OrderProducts
            {
                OrderId   = tempOrder.Id,
                ProductId = productId
            };
            await storeContext.OrdersProducts.AddAsync(newOrderProducts);

            await storeContext.SaveChangesAsync();

            return(tempOrder);
        }
Esempio n. 13
0
        /// <summary>
        ///     Removes the first product that matches the given id parameter in the database.
        /// </summary>
        /// <param name="id">Product Id</param>
        /// <returns></returns>
        public async Task <string> RemoveProductAsync(int id)
        {
            var product = await this.FindProductAsync(id);

            var productName = product.Name;

            if (product.IsDeleted)
            {
                return($"Product {product.Name} was not found.");
            }

            storeContext.Products.Remove(product);
            await storeContext.SaveChangesAsync();

            return($"Product {productName} has been successfully removed.");
        }
Esempio n. 14
0
        /// <summary>
        ///     Deletes an account by changing it's IsDeleted flag and sets the DeletedBy to the commandExecutor's name.
        /// </summary>
        /// <param name="commandExecutor">The username of the command giver.</param>
        /// <param name="accountName">The username of the account to be removed</param>
        /// <returns></returns>
        public async Task DeleteAccountAsync(string accountId)
        {
            var account = await storeContext.Users.FindAsync(accountId);

            if (account == null)
            {
                throw new Exception("Account not found");
            }

            if (!account.IsDeleted) // $"Account {account.UserName} was not found.";

            {
                account.IsDeleted = true;
            }
            account.ModifiedOn = DateTime.Now;
            account.DeletedOn  = DateTime.Now;
            await storeContext.SaveChangesAsync(); // $"Account {account.UserName} has been successfully removed.";
        }
Esempio n. 15
0
        public async Task <Comment> AddCommentToProductAsync(int productId, string commentorId, string commentText)
        {
            var commentor = await storeContext.Accounts.Include(acc => acc.Comments).Where(acc => acc.Id == commentorId)
                            .SingleAsync();

            if (commentor == null)
            {
                throw new UserException("Could not find the user who commented...");
            }

            var productToBeCommentedTo = await storeContext.Products.Include(prod => prod.Comments)
                                         .Where(prod => prod.Id == productId).SingleAsync();

            if (productToBeCommentedTo == null)
            {
                throw new UserException("Could not find product...");
            }

            if (productToBeCommentedTo.Comments.Any(
                    x => x.AccountId == commentor.Id && x.Text == commentText))
            {
                throw new UserException("Cannot add duplicate comments...");
            }

            var newComment = new Comment
            {
                AccountId = commentor.Id,
                Text      = commentText,
                ProductId = productToBeCommentedTo.Id,
                TimeStamp = DateTime.Now,
                IsDeleted = false
            };

            commentor.Comments.Add(newComment);
            storeContext.Accounts.Update(commentor);

            /*  If it doesn't work, remove the comment.
             * productToBeCommentedTo.Comments.Add(newComment);
             * storeContext.Products.Update(productToBeCommentedTo);
             * storeContext.Comments.Add(newComment);*/
            await storeContext.SaveChangesAsync();

            return(newComment);
        }
        public async Task <IActionResult> AddToWishList(int gameId)
        {
            //When user clicks add to wishlist,
            //check if the user has a wishlist if not create it
            //once wishlist is found or created, create wishlist item entry with gameid
            WishList     wl;
            WishListItem wli;
            var          userId = util.GetAccountId(User.Identity.Name);

            var wlRecord = _context.WishList.FirstOrDefault(a => a.AccountId == userId);

            if (wlRecord == null)
            {
                //create wishlist
                wl           = new WishList();
                wl.AccountId = userId;
                wl.IsPublic  = false;

                _context.WishList.Add(wl);
                await _context.SaveChangesAsync();

                wlRecord = _context.WishList.FirstOrDefault(a => a.AccountId == userId);
            }

            wli            = new WishListItem();
            wli.WishListId = wlRecord.WishListId;
            wli.GameId     = gameId;
            _context.WishListItem.Add(wli);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = gameId }));
        }
        /// <summary>
        ///     Adds the given product in the parameters to the account's cart.
        /// </summary>
        /// <param name="product">Product Type</param>
        /// <param name="account">Account Type</param>
        /// <returns></returns>
        public async Task <ShoppingCart> AddToCartAsync(int productId, string accountId)
        {
            var product = await storeContext.Products.FindAsync(productId);

            var account = await storeContext.Accounts.Where(acc => acc.Id == accountId).Include(acc => acc.ShoppingCart)
                          .SingleAsync();

            // Move this check to Commands

            if (product == null)
            {
                throw new UserException("No product given to add.");
            }

            if (await ProductExistsInCartAsync(productId, accountId))
            {
                throw new UserException($"Product {product.Name} already exists in the user's cart.");
            }

            var tempCart = account.ShoppingCart;

            if (tempCart == null)
            {
                throw new UserException($"User ({account.UserName}) doesn't have Shopping Cart.");
            }

            var shoppingCart = new ShoppingCartProducts
            {
                ShoppingCartId = tempCart.Id,
                ProductId      = product.Id
            };

            await storeContext.ShoppingCartProducts.AddAsync(shoppingCart);

            await storeContext.SaveChangesAsync();

            return(tempCart);
        }
        public async Task <IActionResult> AddFriend(int receiverId)
        {
            // Get the sender and receiver's accountIds to create a friendlist connection
            int senderId = _context.Account.FirstOrDefault(a => a.AspuserId == User.Identity.Name).AccountId;
            // Check if a connection has already been created
            bool friendExists = _context.FriendList.FirstOrDefault(a => a.AccountId == senderId && a.FriendId == receiverId) != null;

            if (!friendExists)
            {
                // Create the connection and add it to the database
                FriendList friendList = new FriendList {
                    AccountId = senderId, FriendId = receiverId
                };
                _context.Add(friendList);
                await _context.SaveChangesAsync();
            }

            // View the reciever's profile page
            var profile = _context.Profile.Include(a => a.Account).FirstOrDefault(p => p.AccountId == receiverId);

            return(RedirectToAction("Details", new { id = profile.ProfileId }));
        }
Esempio n. 19
0
 public async Task SaveAsync()
 {
     await _context.SaveChangesAsync();
 }
Esempio n. 20
0
 public void Create(T entity)
 {
     db.Set <T>().Add(entity);
     db.SaveChangesAsync();
 }
 public async Task CreateCart(ShoppingCart cart)
 {
     _db.ShoppingCarts.Add(cart);
     await _db.SaveChangesAsync();
 }
        // POST: Cart/AddToCart/5
        public async Task <IActionResult> AddToCart(int gameId)
        {
            // Get the current user, checking that they are logged in
            var curUser = _context.Account.FirstOrDefault(a => a.AspuserId == User.Identity.Name);

            if (curUser == null)
            {
                // Display NotLoggedIn page
                return(View("NotLoggedIn"));
            }

            // Get the gameStoreContext
            var gameStoreContext = _context.Cart.Include(c => c.CartGame);
            // Get any carts matching the current user's accountId
            var userCart = gameStoreContext.Where(a => a.AccountId == curUser.AccountId);
            // Create a new Cart object
            Cart newCart = new Cart();

            // If there is no cart...
            if (userCart.Count() == 0)
            {
                // Create a new cart with current user's accountId
                newCart.AccountId = curUser.AccountId;
                _context.Cart.Add(newCart);
            }
            // If there is more than 1 cart for an account...
            else if (userCart.Count() > 1)
            {
                // Delete each cart
                foreach (var cart in userCart)
                {
                    await Delete(cart.CartId);
                }
                // Create a new cart with current user's accountId
                newCart.AccountId = curUser.AccountId;
                _context.Cart.Add(newCart);
            }
            else
            {
                // Create a new cart object using the found cart
                // (This is used for consistency with the other If options)
                newCart = userCart.FirstOrDefault();
            }

            await _context.SaveChangesAsync();

            // Create a CartGame object with the gameId and the newCart cartId
            CartGame newCartGame = new CartGame();

            newCartGame.CartId = newCart.CartId;
            newCartGame.GameId = gameId;

            // Add the cartGame object to the context
            _context.CartGame.Add(newCartGame);

            // Save changes and go to the view
            await _context.SaveChangesAsync();

            //return View(await gameStoreContext.ToListAsync());
            return(RedirectToAction("Index"));
        }
Esempio n. 23
0
 public async Task SaveAsync()
 {
     await db.SaveChangesAsync();
 }