Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("id,name")] ShoppingMall shoppingMall)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shoppingMall);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shoppingMall));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("carPlateId,carPlateNumber")] CarPlate carPlate)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carPlate);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(carPlate));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("branchId,branchName,shoppingmallID")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                _context.Add(branch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["shoppingmallID"] = new SelectList(_context.ShoppingMall, "id", "name", branch.shoppingmallID);
            return(View(branch));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("deliveryId,deliveryDate,productLotDate,branchId,shoppingmallID")] Delivery delivery)
        {
            if (ModelState.IsValid)
            {
                _context.Add(delivery);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["branchId"]       = new SelectList(_context.Branch, "id", "name", delivery.branchId);
            ViewData["shoppingmallID"] = new SelectList(_context.ShoppingMall, "id", "name", delivery.shoppingmallID);
            return(View(delivery));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("id,name,code,price")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                Success("create successfully", true);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                Warning("Create Failed!", true);
            }
            return(View(product));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        var user = new ApplicationUser
                        {
                            UserName       = model.Username,
                            FirstName      = model.FirstName,
                            LastName       = model.LastName,
                            EmailConfirmed = true
                        };

                        var result = await _userManager.CreateAsync(user, model.Password);

                        // add role from role id
                        await _userManager.AddToRoleAsync(user, model.RoleId);

                        var data = await _userManager.Users
                                   .Where(x => x.UserName == user.UserName).FirstAsync();

                        if (model.RoleId == "Staff")
                        {
                            var createStaff = new Staff
                            {
                                FirstName         = data.FirstName,
                                LastName          = data.LastName,
                                ApplicationUserId = data.Id
                            };

                            _context.Add(createStaff);
                            await _context.SaveChangesAsync();
                        }
                        else
                        {
                            var createManager = new Manager
                            {
                                FirstName         = data.FirstName,
                                LastName          = data.LastName,
                                ApplicationUserId = data.Id
                            };

                            _context.Add(createManager);
                            await _context.SaveChangesAsync();
                        }

                        transaction.Commit();
                        // Success("Create Successfully!", true);
                        return(RedirectToAction(nameof(UserController.Index)));
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        // Danger("Create Not Complete!", true);
                        return(View(model));
                    }
                }
            }
            // Danger("Model not match!", true);
            return(View(model));
        }