public async Task <ActionResult> Delete(BrandInsertViewModel viewModel)
        {
            Response response = new Response();

            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <BrandInsertViewModel, BrandDTO>();
            });

            IMapper mapper = configuration.CreateMapper();

            BrandDTO dto = mapper.Map <BrandDTO>(viewModel);

            response = await _service.Delete(dto.ID);

            //Se funcionou, redireciona pra página inicial
            if (response.Success)
            {
                return(RedirectToAction("Index", "Brand"));
            }
            else
            {
                ViewBag.ErrorMessage = response.Errors;
                return(this.View());
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Insert(BrandInsertViewModel viewmodel)
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <BrandInsertViewModel, BrandDTO>();
            });
            IMapper mapper = configuration.CreateMapper();
            // new SERService().GetSERByID(4);
            //Transforma o ClienteInsertViewModel em um ClienteDTO
            BrandDTO dto = mapper.Map <BrandDTO>(viewmodel);

            try
            {
                await _brandService.Insert(dto);

                return(RedirectToAction("Get", "Brand"));
            }
            catch (Exception ex)
            {
                ViewBag.Erros = ex.Message;
            }
            return(View());
        }
        public async Task <ActionResult> Register(BrandInsertViewModel viewModel)
        {
            Response response = new Response();

            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <BrandInsertViewModel, BrandDTO>();
            });
            IMapper mapper = configuration.CreateMapper();

            BrandDTO dto = mapper.Map <BrandDTO>(viewModel);

            response = await _service.Insert(dto);

            if (response.Success)
            {
                return(RedirectToAction("Index", "Brand"));
            }
            else
            {
                ViewBag.ErrorMessage = response.Errors;
                return(this.View());
            }
        }