public async Task <ActionResult> EditRegion(SaveEditRegionViewModel region)
        {
            bool isEdited = false;

            if (ModelState.IsValid)
            {
                var res = mapper.Map <SaveEditRegionViewModel, Region>(region);
                isEdited = await _placesService.EditRegion(res);

                if (!isEdited)
                {
                    ModelState.AddModelError("region.Code", "El código ya está registrado");
                }
            }
            var regionMunicipalities = await _placesService.GetMunicipalitiesByRegion(region.Id);

            var listMunicipalities = mapper.Map <List <Municipality>, List <MunicipalityViewModel> >(regionMunicipalities);

            RegionViewModel viewRegion = new RegionViewModel()
            {
                Code = region.Code,
                Id   = region.Id,
                Name = region.Name
            };

            EditRegionViewModel viewModel = new EditRegionViewModel()
            {
                Region         = viewRegion,
                Municipalities = listMunicipalities,
                OriginalName   = (isEdited) ? region.Name : region.OriginalName
            };

            return(View(viewModel));
        }
Exemplo n.º 2
0
        // GET: Regions/Edit/5
        public async Task <ActionResult> Edit(Guid id)
        {
            if (id == null)
            {
                Alert($"Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var result = await _regionService.FindById(id);

                if (result.Success)
                {
                    var regionResource = new EditRegionViewModel
                    {
                        RegionId          = result.Data.Id,
                        RegionDescription = result.Data.Description,
                        RegionName        = result.Data.Name
                    };

                    return(View(regionResource));
                }
                else
                {
                    Alert($"Error! : {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }
            }
            catch (Exception ex)
            {
                Alert($"An Error Occurred While Fetching The Requested Resource. {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult> EditRegion(Guid id, EditRegionViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            if (!id.Equals(request.RegionId))
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var regionEditRequest = new UpdateRegionRequest {
                    CountryId = request.CountryId, Description = request.RegionDescription, Name = request.RegionName, Id = request.RegionId
                };
                var result = await _regionService.Update(id, regionEditRequest);

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

                Alert($"Unit Of Measure Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Regions), new { id = request.CountryId }));
            }
            catch
            {
                Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
Exemplo n.º 4
0
        public async Task <ActionResult> EditRegion(Guid id)
        {
            var region = new EditRegionViewModel();

            try
            {
                var result = await _regionService.FindByIdInclusive(id, x => x.Include(p => p.Country));

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View(region));
                }
                region.RegionId          = result.Data.Id;
                region.RegionName        = result.Data.Name;
                region.RegionDescription = result.Data.Description;
                region.CountryId         = result.Data.Country.Id;
                region.CountryName       = result.Data.Country.Name;
                return(View(region));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View(region));
            }
        }
Exemplo n.º 5
0
        public ActionResult Edit(int id)
        {
            var model = new EditRegionViewModel();

            PrepareViewModel(model, EvolutionResources.bnrAddEditRegion);

            model.Region           = LookupService.FindRegionModel(id);
            model.Region.CompanyId = model.CurrentCompany.Id;
            model.LGS = LookupService.LockRegion(model.Region);

            return(View(model));
        }
        public async Task <ActionResult> EditRegion(string id)
        {
            var region = await _placesService.GetRegion(id);

            if (region != null)
            {
                var regionMunicipalities = await _placesService.GetMunicipalitiesByRegion(region.Id);

                var regionViewModel           = mapper.Map <Region, RegionViewModel>(region);
                var listMunicipalities        = mapper.Map <List <Municipality>, List <MunicipalityViewModel> >(regionMunicipalities);
                EditRegionViewModel viewModel = new EditRegionViewModel()
                {
                    Region         = regionViewModel,
                    Municipalities = listMunicipalities,
                    OriginalName   = regionViewModel.Name
                };
                return(View(viewModel));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
 public ActionResult Save(EditRegionViewModel model, string command)
 {
     if (command.ToLower() == "save")
     {
         var modelError = LookupService.InsertOrUpdateRegion(model.Region, CurrentUser, model.LGS);
         if (modelError.IsError)
         {
             PrepareViewModel(model, EvolutionResources.bnrAddEditRegion);
             model.SetErrorOnField(ErrorIcon.Error,
                                   modelError.Message,
                                   "Region_" + modelError.FieldName);
             return(View("Edit", model));
         }
         else
         {
             return(RedirectToAction("Regions"));
         }
     }
     else
     {
         return(RedirectToAction("Regions"));
     }
 }
Exemplo n.º 8
0
        public async Task <ActionResult> Edit(Guid id, EditRegionViewModel editRegionRequest)
        {
            if (!ModelState.IsValid)
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            if (!id.Equals(editRegionRequest.RegionId))
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                UpdateRegionRequest updateRegionRequest = new UpdateRegionRequest {
                    Id = editRegionRequest.RegionId, Name = editRegionRequest.RegionName, Description = editRegionRequest.RegionDescription
                };
                var result = await _regionService.Update(id, updateRegionRequest);

                if (result.Success)
                {
                    Alert($"Region Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }
            }
            catch
            {
                Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }