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

                var viewModel = new SellerformViewModel {
                    Seller = seller, Departments = department
                };
                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 (ApplicationException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create()
        {
            var departments = await _departmentService.FindAllAsync();

            var viewModel = new SellerformViewModel {
                Departments = departments
            };

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

                var viewModel = new SellerformViewModel {
                    Seller = seller, Departments = departments
                };
                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();

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

            return(View(viewModel));
        }