示例#1
0
        public async Task <IActionResult> Edit(int id, Seller seller)
        {
            if (!ModelState.IsValid)
            {
                var departament = await _departmentService.FindAllAsync();

                var viewModel = new SellerFomViewModel {
                    Seller = seller, Departments = departament
                };
                return(View(viewModel));
            }
            if (id != seller.Id)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id mismatch" }));
            }
            try
            {
                await _sellerService.UpdateAsync(seller);

                return(RedirectToAction(nameof(Index)));
            }
            catch (NotFoundException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
示例#2
0
        public async Task <IActionResult> Create()
        {
            var departments = await _departmentService.FindAllAsync();

            var viewModel = new SellerFomViewModel {
                Departments = departments
            };

            return(View(viewModel));
        }
示例#3
0
        public async Task <IActionResult> Create(Seller seller)
        {
            if (!ModelState.IsValid)
            {
                var departament = await _departmentService.FindAllAsync();

                var viewModel = new SellerFomViewModel {
                    Seller = seller, Departments = departament
                };
                return(View(viewModel));
            }
            await _sellerService.InsertAsync(seller);

            return(RedirectToAction(nameof(Index)));
        }
示例#4
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id not provided" }));
            }
            var obj = await _sellerService.FindByIdAsync(id.Value);

            if (obj == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id not found" }));
            }
            List <Department> departments = await _departmentService.FindAllAsync();

            SellerFomViewModel viewModel = new SellerFomViewModel {
                Seller = obj, Departments = departments
            };

            return(View(viewModel));
        }