public async Task <ActionResult> DeleteRegion(Guid id, RegionDetailsViewModel request) { if (!ModelState.IsValid) { Alert("Bad Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Regions), new { id = request.CountryId })); } if (id == null) { Alert($"Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Regions), new { id = request.CountryId })); } try { var result = await _regionService.Delete(id); if (!result.Success) { Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Regions), new { id = request.CountryId })); } Alert($"Region {request.RegionName} Deleted 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(RedirectToAction(nameof(Regions), new { id = request.CountryId })); } }
public async Task <ActionResult> DeleteRegion(Guid id) { if (id == null) { Alert($"Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } var region = new RegionDetailsViewModel(); 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.RegionCode = result.Data.Code; region.RegionId = result.Data.Id; region.RegionName = result.Data.Name; region.RegionDescription = result.Data.Description; region.DateCreated = result.Data.CreatedAt; region.DateLastUpdated = result.Data.LastUpdated; region.CountryName = result.Data.Country.Name; region.CountryId = result.Data.Country.Id; return(View(region)); } catch (Exception ex) { Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(region)); } }