Example #1
0
        public async Task <IActionResult> Create(string passwordConfirm, [Bind("UserId,UserName,PasswordHash,FirstName,Dob,LastName,Phone,Email,Gender,ReceivePromotionalEmails")] WizardsUser users)
        {
            Boolean isValid = true;

            if (string.IsNullOrEmpty(users.PasswordHash) || passwordConfirm != users.PasswordHash)
            {
                isValid = false;
                TempData["PasswordConfirmMessage"] = "Password does not match.";
            }
            if (_context.WizardsUser.Where(u => u.UserName.Equals(users.UserName)).Any())
            {
                isValid = false;
                TempData["UserExistedMessage"] = "Username is used by another user.";
            }
            if (isValid && ModelState.IsValid)
            {
                users.PasswordHash = HashHelper.ComputeHash(users.PasswordHash);
                UserRole userRole = new UserRole();

                // Assign "Customer" role to the new user
                userRole.Role = _context.WizardsRole.Where(r => r.RoleName.Equals("Customer")).FirstOrDefault();
                userRole.User = users;
                _context.Add(users);
                _context.Add(userRole);
                await _context.SaveChangesAsync();

                CreateUserSession(users);

                return(RedirectToAction("index", "home"));
            }
            ViewData["Gender"] = new SelectList(_context.Gender, "Gender1", "Gender1", users.Gender);
            return(View(users));
        }
Example #2
0
        public async Task <IActionResult> Create(string receiverUserName, [Bind("Sender,Receiver,IsFamily,IsAccepted")] Relationship relationship)
        {
            var receiver = _context.WizardsUser.Where(u => u.UserName == receiverUserName).FirstOrDefault();

            if (receiver != null)
            {
                relationship.Receiver = receiver.UserId;

                /*if (ModelState.IsValid)
                 * {*/
                relationship.IsAccepted = false;
                _context.Add(relationship);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                TempData["Message"] = "Request has been sent successfully!";
                //}
            }
            else
            {
                TempData["Message"] = "Username does not exist.";
            }
            var sessionUserId = UserHelper.GetSessionUserId(this);

            ViewData["UserId"] = sessionUserId;
            return(View(relationship));
        }
        public async Task <IActionResult> Create([Bind("Gender1")] Gender gender)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gender);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gender));
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("GameCategoryId,GameCategory1")] GameCategory gameCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gameCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gameCategory));
        }
        public async Task <IActionResult> Create([Bind("ProvinceCode,ProvinceName")] Province province)
        {
            if (ModelState.IsValid)
            {
                _context.Add(province);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(province));
        }
Example #6
0
        public async Task <IActionResult> Create([Bind("UserId,RoleId")] UserRole userRole)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userRole);
                await _context.SaveChangesAsync();

                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> Create([Bind("OrderId, GameId, Quantity, IsDigital")] OrderDetail orderDetail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewData["Games"] = new SelectList(_context.Game, "GameId", "GameName");
            return(View(orderDetail));
        }
        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));
        }
Example #9
0
        public async Task <IActionResult> Create([FromForm(Name = "imageFile")] IFormFile imageFile, [Bind("GameImageId,GameId")] GameImage gameImage, bool isThumbnail = false)
        {
            if (true) //ModelState.IsValid
            {
                string filePath = UploadedFile(gameImage.GameId, imageFile, isThumbnail);
                gameImage.GameImagePath = filePath;
                _context.Add(gameImage);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Admin", "Games"));
            }
            //ViewData["GameId"] = new SelectList(_context.Game, "GameId", "GameName", gameImage.GameId);
            ViewData["GameId"] = gameImage.GameId;
            return(View(gameImage));
        }
        public async Task <IActionResult> Create([Bind("AddressId,UserId,Street1,Street2,City,ProvinceCode,PostalCode,AddressTypeId")] Address address)
        {
            if (ModelState.IsValid)
            {
                _context.Add(address);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProvinceCode"]  = new SelectList(_context.Province, "ProvinceCode", "ProvinceName", address.ProvinceCode);
            ViewData["AddressTypeId"] = new SelectList(_context.AddressType, "AddressTypeId", "AddressTypeName");
            //ViewData["UserId"] = new SelectList(_context.WizardsUser, "UserId", "Email", address.UserId);
            if (UserHelper.IsLoggedIn(this))
            {
                ViewData["UserId"] = HttpContext.Session.GetInt32("userId");
            }
            return(View(address));
        }
        public async Task <IActionResult> Create([Bind("CreditCardId,UserId,CreditCardNumber,ExpiryDate,Cvc,CardHolder")] CreditCard creditCard)
        {
            if (ModelState.IsValid)
            {
                encodeData(creditCard);
                creditCard.ExpiryDate = creditCard.ExpiryDate.Replace("/", "");
                _context.Add(creditCard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            //ViewData["UserId"] = new SelectList(_context.WizardsUser, "UserId", "UserName", creditCard.UserId);
            if (UserHelper.IsLoggedIn(this))
            {
                ViewData["UserId"] = HttpContext.Session.GetInt32("userId");
            }
            return(View(creditCard));
        }
        // GET: Ratings/Create
        //public IActionResult Create(int gameId, int rate)
        //{
        //    if (!UserHelper.IsLoggedIn(this)) return UserHelper.RequireLogin(this);

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

        // POST: Ratings/Create
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create(int gameId, int rate) //[Bind("RatingId,Rate,UserId,GameId")] Rating rating
        {
            if (!UserHelper.IsLoggedIn(this))
            {
                return(UserHelper.RequireLogin(this));
            }
            var    userId = UserHelper.GetSessionUserId(this);
            Rating rating = new Rating();

            rating.Rate   = (double)rate;
            rating.UserId = (int)userId;
            rating.GameId = gameId;

            _context.Add(rating);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", "Games", new { id = gameId }));
            //return View(rating);
        }
        public async Task <IActionResult> Create([Bind("ReviewId,ReviewContent,UserId,GameId")] Review review)
        {
            if (UserHelper.IsLoggedIn(this))
            {
                ViewData["UserId"] = HttpContext.Session.GetInt32("userId");
            }

            if (ModelState.IsValid)
            {
                review.ReviewDate  = DateTime.Now;
                review.IsPublished = false;
                _context.Add(review);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Games", new { id = review.GameId }));
                //return RedirectToAction(nameof(Index));
            }

            return(View(review));
        }
Example #14
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));
        }
        public async Task <IActionResult> Create([Bind("UserId,GameCategoryId")] FavoriteCategory favoriteCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(favoriteCategory);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                //return View(favoriteCategory);
            }

            var userId = UserHelper.GetSessionUserId(this);
            var favoriteCategoryContext = _context.FavoriteCategory
                                          .Include(f => f.GameCategory)
                                          .Where(f => f.UserId.Equals(userId));

            ViewData["UserId"]             = userId;
            ViewData["FavoriteCategories"] = favoriteCategoryContext.ToList();
            ViewData["GameCategories"]     = getCategoriesNotInFav(userId);

            return(View(favoriteCategory));
        }
Example #16
0
        public async Task <IActionResult> Create([Bind("UserId,PlatformId")] FavoritePlatform favoritePlatform)
        {
            if (ModelState.IsValid)
            {
                _context.Add(favoritePlatform);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                //return View(favoritePlatform);
            }
            //ViewData["PlatformId"] = new SelectList(_context.Platform, "PlatformId", "PlatformName", favoritePlatform.PlatformId);

            var userId = UserHelper.GetSessionUserId(this);
            var favoritePlatformContext = _context.FavoritePlatform
                                          .Include(f => f.Platform)
                                          .Where(f => f.UserId.Equals(userId));

            ViewData["UserId"]            = userId;
            ViewData["FavoritePlatforms"] = favoritePlatformContext.ToList();
            ViewData["Platforms"]         = getPlatformsNotInFav(userId);

            return(View(favoritePlatform));
        }