public async Task <ActionResult> Create([Bind("OrderId, UserId, CreditCardId, MailingAddressId, ShippingAddressId, OrderStatusId, Total")] WizardsOrder order)
        {
            var sessionUserId = UserHelper.GetSessionUserId(this);

            if (ModelState.IsValid)
            {
                var cart = CartHelper.getCartFromSession(this);
                order.UserId        = (int)sessionUserId;
                order.OrderStatusId = 1; //Default is processing
                order.Total         = calculateTotal(cart);
                _context.Add(order);
                await _context.SaveChangesAsync();

                foreach (var item in cart)
                {
                    // Update order details
                    OrderDetail od = new OrderDetail()
                    {
                        OrderId = order.OrderId, GameId = item.Game.GameId, Quantity = item.Quantity, IsDigital = item.IsDigital
                    };
                    _context.Add(od);

                    // Update game quantity
                    if (!item.IsDigital)
                    {
                        var game = _context.Game.Find(item.Game.GameId);
                        game.GameQty = (short)(game.GameQty - item.Quantity);
                        _context.Update(game);
                    }
                }

                await _context.SaveChangesAsync();

                CartHelper.clearCart(this);
                return(RedirectToAction("Index"));
            }

            var cardList = _context.CreditCard.Where(c => c.UserId == sessionUserId);
            await cardList.ForEachAsync(c => c.CreditCardNumber = Base64Helper.decode(c.CreditCardNumber));

            ViewData["UserId"]            = sessionUserId;
            ViewData["CreditCardId"]      = new SelectList(cardList, "CreditCardId", "CreditCardNumber");
            ViewData["MailingAddressId"]  = new SelectList(_context.Address.Include(a => a.AddressType).Where(a => a.AddressTypeId == 1 && a.UserId == sessionUserId), "AddressId", "Street1");
            ViewData["ShippingAddressId"] = new SelectList(_context.Address.Include(a => a.AddressType).Where(a => a.AddressTypeId == 2 && a.UserId == sessionUserId), "AddressId", "Street1");
            ViewData["OrderStatusId"]     = 1; // Default to Processing
            ViewData["Total"]             = calculateTotal(CartHelper.getCartFromSession(this));

            return(View(order));
        }
        public async Task <IActionResult> Edit(string id, [Bind("Gender1")] Gender gender)
        {
            if (id != gender.Gender1)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(gender);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GenderExists(gender.Gender1))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(gender));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,RoleId")] UserRole userRole)
        {
            if (id != userRole.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userRole);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserRoleExists(userRole.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoleId"] = new SelectList(_context.WizardsRole, "RoleId", "RoleName", userRole.RoleId);
            ViewData["UserId"] = new SelectList(_context.WizardsUser, "UserId", "Email", userRole.UserId);
            return(View(userRole));
        }
        public async Task <ActionResult> Edit(int orderId, int gameId, [Bind("OrderId, GameId, Quantity, IsDigital")] OrderDetail orderDetail)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(orderDetail);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(orderDetail.OrderId, orderDetail.GameId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(orderDetail));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(short id, [Bind("GameCategoryId,GameCategory1")] GameCategory gameCategory)
        {
            if (id != gameCategory.GameCategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(gameCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GameCategoryExists(gameCategory.GameCategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(gameCategory));
        }
        public async Task <IActionResult> Edit(string id, [Bind("ProvinceCode,ProvinceName")] Province province)
        {
            if (id != province.ProvinceCode)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(province);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProvinceExists(province.ProvinceCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(province));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ReviewId,ReviewContent,UserId,GameId,ReviewDate,IsPublished")] Review review)
        {
            if (id != review.ReviewId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(review);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewExists(review.ReviewId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(review));
        }
        public async Task <IActionResult> Edit(int id, [Bind("CreditCardId,UserId,CreditCardNumber,ExpiryDate,Cvc,CardHolder")] CreditCard creditCard)
        {
            if (id != creditCard.CreditCardId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    creditCard.ExpiryDate = creditCard.ExpiryDate.Replace("/", "");
                    encodeData(creditCard);
                    _context.Update(creditCard);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CreditCardExists(creditCard.CreditCardId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            //ViewData["UserId"] = new SelectList(_context.WizardsUser, "UserId", "UserName", creditCard.UserId);
            return(View(creditCard));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Edit(int id, [Bind("Sender,Receiver,IsFamily,IsAccepted")] Relationship relationship)
        {
            if (id != relationship.Sender)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(relationship);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RelationshipExists(relationship.Sender))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Sender"]   = new SelectList(_context.WizardsUser, "UserId", "Email", relationship.Sender);
            ViewData["Receiver"] = new SelectList(_context.WizardsUser, "UserId", "Email", relationship.Receiver);
            return(View(relationship));
        }
        public async Task <IActionResult> Edit(int id, [Bind("AddressId,UserId,Street1,Street2,City,ProvinceCode,PostalCode, AddressTypeId")] Address address)
        {
            if (id != address.AddressId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(address);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AddressExists(address.AddressId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProvinceCode"]  = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", address.ProvinceCode);
            ViewData["AddressTypeId"] = new SelectList(_context.AddressType, "AddressTypeId", "AddressTypeName");
            //ViewData["UserId"] = new SelectList(_context.WizardsUser, "UserId", "Email", address.UserId);
            return(View(address));
        }
        // GET: Ratings/Edit/5
        //public async Task<IActionResult> Edit(int? id)
        //{
        //    if (id == null)
        //    {
        //        return NotFound();
        //    }

        //    var rating = await _context.Rating.FindAsync(id);
        //    if (rating == null)
        //    {
        //        return NotFound();
        //    }

        //    if (!UserHelper.IsLoggedIn(this)) return UserHelper.RequireLogin(this);

        //    ViewData["UserId"] = HttpContext.Session.GetInt32("userId");
        //    return View(rating);
        //}

        // POST: Ratings/Edit/5
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Edit(int gameId, int rate) //int id, [Bind("RatingId,Rate,UserId,GameId")] Rating rating
        {
            if (!UserHelper.IsLoggedIn(this))
            {
                return(UserHelper.RequireLogin(this));
            }
            var userId = UserHelper.GetSessionUserId(this);
            var rating = await _context.Rating.FirstOrDefaultAsync(r => r.GameId.Equals(gameId) && r.UserId.Equals(userId));

            if (rating == null)
            {
                return(NotFound());
            }

            try
            {
                rating.Rate = rate;

                _context.Update(rating);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RatingExists(rating.GameId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToAction("Details", "Games", new { id = gameId }));
        }
        public async Task <IActionResult> Edit(int id, [Bind("UserId,GameCategoryId")] FavoriteCategory favoriteCategory)
        {
            if (id != favoriteCategory.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(favoriteCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FavoriteCategoryExists(favoriteCategory.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            if (UserHelper.IsLoggedIn(this))
            {
                ViewData["UserId"] = HttpContext.Session.GetInt32("userId");
            }
            ViewData["GameCategoryId"] = new SelectList(_context.GameCategory, "GameCategoryId", "GameCategory1", favoriteCategory.GameCategoryId);
            return(View(favoriteCategory));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Edit(int id, [Bind("GameImageId,GameId,GameImagePath")] GameImage gameImage)
        {
            if (id != gameImage.GameImageId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(gameImage);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GameImageExists(gameImage.GameImageId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GameId"] = new SelectList(_context.Game, "GameId", "GameDigitalPath", gameImage.GameId);
            return(View(gameImage));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,UserName,FirstName,Dob,LastName,Phone,Email,Gender,ReceivePromotionalEmails")] WizardsUser users)
        {
            //if (id == null && IsLoggedIn())
            //{
            //    int sessionUserId = HttpContext.Session.GetInt32("userId");
            //    id = sessionUserId;
            //}

            if (id != users.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var userToUpdate = _context.WizardsUser.Where(u => u.UserId.Equals(users.UserId)).FirstOrDefault();
                    userToUpdate.FirstName = users.FirstName;
                    userToUpdate.LastName  = users.LastName;
                    userToUpdate.Gender    = users.Gender;
                    userToUpdate.Email     = users.Email;
                    userToUpdate.Dob       = users.Dob;
                    userToUpdate.Phone     = users.Phone;
                    userToUpdate.ReceivePromotionalEmails = users.ReceivePromotionalEmails;

                    _context.Update(userToUpdate);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserHelper.UserExists(users.UserId, _context))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Menu)));
            }
            ViewData["Gender"] = new SelectList(_context.Gender, "Gender1", "Gender1", users.Gender);
            return(View(users));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Create([Bind("GameId,GameStatusCode,GamePlatformId,GameCategoryId,GameName,GameDescription,GamePrice,GameQty")] Game game,
                                                 [FromForm(Name = "gameFile")] IFormFile gameFile = null)
        {
            if (ModelState.IsValid)
            {
                _context.Add(game);
                await _context.SaveChangesAsync();

                if (gameFile != null)
                {
                    game.GameDigitalPath = UploadedFile(game.GameId, gameFile);
                    _context.Update(game);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Admin)));
            }
            ViewData["GamePlatformId"] = new SelectList(_context.Platform, "PlatformId", "PlatformName");
            ViewData["GameCategoryId"] = new SelectList(_context.GameCategory, "GameCategoryId", "GameCategory1", game.GameCategoryId);
            ViewData["GameStatusCode"] = new SelectList(_context.GameStatus, "GameStatusCode", "GameStatus1", game.GameStatusCode);
            return(View(game));
        }