public async Task <ActionResult> Edit(Guid id, EditBrandViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            if (!id.Equals(request.Id))
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var brandUpdateRequest = new UpdateBrandRequest {
                    Id = request.Id, Name = request.Name, Description = request.Description
                };
                var result = await _brandService.Update(id, brandUpdateRequest);

                if (!result.Success)
                {
                    Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }

                Alert($"Brand Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
        public async Task <IActionResult> EditBrand([FromRoute] int id, EditBrandViewModel editBrandViewModel)
        {
            if (ModelState.IsValid)
            {
                if (id == editBrandViewModel.BrandId)
                {
                    using (var client = _restClient.CreateClient(User))
                    {
                        using (
                            var response = await client.PutAsync("/api/brand",
                                                                 new StringContent(JsonConvert.SerializeObject(editBrandViewModel), Encoding.UTF8,
                                                                                   "application/json")))
                        {
                            if (response.StatusCode == HttpStatusCode.OK)
                            {
                                return(RedirectToAction("Brands"));
                            }
                        }
                    }
                }

                ModelState.AddModelError(String.Empty, "Update failed");
            }


            return(View(editBrandViewModel));
        }
Exemple #3
0
        public ActionResult Edit(int id)
        {
            var model = new EditBrandViewModel();

            prepareEditModel(model);

            model.Brand = ProductService.FindBrandModel(id);
            model.LGS   = ProductService.LockBrand(model.Brand);

            return(View(model));
        }
        public ActionResult UpdateBrand(EditBrandViewModel editBrandViewModel)
        {
            var config = new MapperConfiguration(mapping =>
            {
                mapping.CreateMap <EditBrandViewModel, Brand>().IgnoreAllNonExisting();
            });
            IMapper mapper = config.CreateMapper();
            Brand   brand  = mapper.Map <EditBrandViewModel, Brand>(editBrandViewModel);

            brandBL.UpdateBrand(brand);
            return(RedirectToAction("Index", "Home"));
        }
        public IActionResult Update(EditBrandViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model = _brandWebService.GetBrandById(model.Id);
                return View($"{BrandsViewFolder}/Edit.cshtml", model);
            }

            BaseWebServiceResponse response = _brandWebService.Update(model);
            TempData[BrandActionName] = JsonConvert.SerializeObject(response);

            if (!response.ActionSuccessful)
            {
                return View($"{BrandsViewFolder}/Index.cshtml", model);
            }

            return RedirectToAction("Index", "Brands");
        }
        public BaseWebServiceResponse Update(EditBrandViewModel model)
        {
            var brandDto        = mapper.Map <EditBrandViewModel, BrandDTO>(model);
            var brandNameExists = _brandService.BrandNameExists(brandDto);

            var response = new BaseWebServiceResponse
            {
                ActionSuccessful = brandNameExists,
                Error            = brandNameExists ?
                                   null :
                                   new ErrorServiceViewModel()
                {
                    Name    = "Brand Name",
                    Message = "Brand Name is already in use."
                }
            };

            if (response.Error != null)
            {
                return(response);
            }

            var brandAdded = _brandService.Update(brandDto);

            if (!brandAdded)
            {
                response.ActionSuccessful = false;
                response.Error            = brandNameExists ?
                                            null :
                                            new ErrorServiceViewModel()
                {
                    Name    = "Brand",
                    Message = "There was a problem updating the Brand. We have been notified of the error but please try again."
                };
            }

            response.ActionSuccessful = true;
            response.SuccessMessage   = "Brand successfully updated";
            return(response);
        }
Exemple #7
0
 public ActionResult Save(EditBrandViewModel model, string command)
 {
     if (command.ToLower() == "save")
     {
         var modelError = ProductService.InsertOrUpdateBrand(model.Brand, CurrentUser, model.LGS);
         if (modelError.IsError)
         {
             prepareEditModel(model);
             model.SetErrorOnField(ErrorIcon.Error,
                                   modelError.Message,
                                   "Brand_" + modelError.FieldName);
             return(View("Edit", model));
         }
         else
         {
             return(RedirectToAction("Brands"));
         }
     }
     else
     {
         return(RedirectToAction("Brands"));
     }
 }
        public async Task <IActionResult> EditBrand([FromRoute] int id)
        {
            var brand = new EditBrandViewModel();

            using (var client = _restClient.CreateClient(User))
            {
                using (
                    var response = await client.GetAsync("/api/brand/" + id))
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        brand = JsonConvert.DeserializeObject <EditBrandViewModel>(
                            await response.Content.ReadAsStringAsync());
                    }
                    else
                    {
                        return(RedirectToAction("Brands"));
                    }
                }
            }

            return(View(brand));
        }
        // GET: Brands/Edit/5
        public async Task <ActionResult> Edit(Guid id)
        {
            var brand = new EditBrandViewModel();

            try
            {
                var result = await _brandService.FindById(id);

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View(brand));
                }
                brand.Id          = result.Data.Id;
                brand.Name        = result.Data.Name;
                brand.Description = result.Data.Description;
                return(View(brand));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View(brand));
            }
        }
Exemple #10
0
 void prepareEditModel(EditBrandViewModel model)
 {
     PrepareViewModel(model, EvolutionResources.bnrAddEditBrand, 0, MenuOptionFlag.RequiresNoProduct);
     model.BrandCategoryList = ProductService.FindBrandCategoryListItemModel(model.CurrentCompany);
 }
 public IActionResult Edit(int brandId)
 {
     EditBrandViewModel model = _brandWebService.GetBrandById(brandId);
     return View($"{BrandsViewFolder}/Edit.cshtml", model);
 }