Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, Seller seller)
        {
            if (!ModelState.IsValid)
            {
                var departments = await _departmentService.FindAllAsync();

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

                return(RedirectToAction(nameof(Index)));
            }
            catch (ApplicationException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                //return NotFound();
                return(RedirectToAction(nameof(Error), new { message = "Id not found" }));
            }

            var obj = await _sellerService.FindByIdAsync(id.Value);

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

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

            // passa para a view do MVC
            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public IActionResult Create()
        {
            var departments = _departmentService.FindAll();
            var viewModel   = new SellerFormViewModels {
                Departments = departments
            };

            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create()
        {
            var departments = await _departmentService.FindAllAsync();

            var viewModel = new SellerFormViewModels {
                Departments = departments
            };

            return(View(viewModel));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create(Seller seller)
        {
            if (!ModelState.IsValid)
            {
                var departments = await _departmentService.FindAllAsync();

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

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 6
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();

            SellerFormViewModels viewModels = new SellerFormViewModels {
                Seller = obj, Departments = departments
            };

            return(View(viewModels));
        }
Ejemplo n.º 7
0
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var obj = _sellerService.FindById(id.Value);

            if (obj == null)
            {
                return(NotFound());
            }
            List <Department>    departments = _departmentService.FindAll();
            SellerFormViewModels viewModel   = new SellerFormViewModels {
                Seller = obj, Departments = departments
            };

            return(View(viewModel));
        }
Ejemplo n.º 8
0
        [ValidateAntiForgeryToken]  // previne ataques CSRF
        public async Task <IActionResult> Edit(int id, Seller seller)
        {
            if (!ModelState.IsValid)
            {
                var departments = await _departmentService.FindAllAsync();

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

                return(RedirectToAction(nameof(Index)));
            }
            //catch (NotFoundException e)
            catch (ApplicationException e)
            {
                //return NotFound();
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }

            /*
             * catch (DbConcurrencyException e)
             * {
             *  //return BadRequest();
             *  return RedirectToAction(nameof(Error), new { message = e.Message });
             * }
             */
        }