Beispiel #1
0
        public async Task <ServiceResponse <Region> > Update(Guid id, UpdateRegionRequest request)
        {
            try
            {
                var country = await _countryService.FindById(request.CountryId);

                if (!country.Success)
                {
                    return(new ServiceResponse <Region>($"The provided Country was not found"));
                }
                var region = await _regionRepository.GetById(id);

                region.Name        = request.Name;
                region.CountryId   = request.CountryId;
                region.Description = request.Description;

                await _regionRepository.Update(region);

                return(new ServiceResponse <Region>(region));
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <Region>($"An Erroe Occured while updating Region Resource. {ex.Message}"));
            }
        }
Beispiel #2
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());
            }
        }
        public async Task <int> UpdateRegion(int regionId, UpdateRegionRequest request)
        {
            var existRegion = await _context.Regions.FirstOrDefaultAsync(region => region.regionId.Equals(regionId));

            if (existRegion != null)
            {
                existRegion.name = request.name;
                existRegion.code = request.code;
                existRegion.shop = request.shop;
            }
            return(await _context.SaveChangesAsync());
        }
Beispiel #4
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());
            }
        }