public ActionResult DeleteLoc(LocationDeleteViewModel model) { try { int id = Convert.ToInt32(model.LocationID); if (_uow.Repository <TRN_SAMPLE_TB>().Find(u => u.N_LOCATION_SYSID == id).Count() > 0) { model.ShowMessage = true; model.Message = "Sample records exist for this location. Sorry, the location can not be deleted."; return(View("DeleteLoc", model)); } else { _uow.Repository <REF_LOCATION_TB>().Delete(id); _uow.SaveChanges(); return(RedirectToAction("Index", new { ID = id })); } } catch (Exception ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: LocationController.DeleteLoc_POST\n\nError: " + ex.Message; } else { ViewBag.Message = "Function: LocationController.DeleteLoc_POST\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message); }; Session["ErrorMessage"] = ViewBag.Message; return(RedirectToAction("InternalServerError", "Error")); }; }
public IActionResult DeleteLocation(LocationDeleteViewModel locationDeleteViewModel) { if (locationDeleteViewModel.LocationDelete == LocationDelete.Delete) { int?UKPRN = Session.GetInt32("UKPRN"); if (!UKPRN.HasValue) { return(RedirectToAction("Index", "Home", new { errmsg = "Please select a Provider." })); } var updatedVenue = _venueService .GetVenueByIdAsync(new GetVenueByIdCriteria(locationDeleteViewModel.VenueId.ToString())).Result .Value; updatedVenue.Status = VenueStatus.Deleted; updatedVenue = _venueService.UpdateAsync(updatedVenue).Result.Value; VenueSearchResultItemModel deletedVenue = new VenueSearchResultItemModel( HtmlEncoder.Default.Encode(updatedVenue.VenueName), updatedVenue.Address1, updatedVenue.Address2, updatedVenue.Town, updatedVenue.County, updatedVenue.PostCode, updatedVenue.ID); return(RedirectToAction("LocationConfirmationDelete", "Locations", new{ VenueId = updatedVenue.ID })); } return(RedirectToAction("Index", "Venues")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } LocationDeleteVM = await _context.Location.Select(l => new LocationDeleteViewModel() { LocationID = l.LocationID, LocationCode = l.LocationCode, DivisionName = l.Division.DivisionName, AddressID = l.AddressID, StateProvince = l.Address.StateProvince, Country = l.Address.Country }).FirstOrDefaultAsync(l => l.LocationID == id); var locationToDelete = new Location { LocationID = LocationDeleteVM.LocationID, LocationCode = LocationDeleteVM.LocationCode, AddressID = LocationDeleteVM.AddressID, Address = new Address { AddressID = LocationDeleteVM.AddressID, StateProvince = LocationDeleteVM.StateProvince, Country = LocationDeleteVM.Country } /* * Address = new Address * { * StateProvince = LocationDeleteVM.StateProvince, * Country = LocationDeleteVM.Country * }*/ }; if (locationToDelete != null) { _context.Location.Remove(locationToDelete); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public ActionResult DeleteLoc(string ID, string SearchText) { try { int id = Convert.ToInt32(ID); REF_LOCATION_TB location = _uow.Repository <REF_LOCATION_TB>().GetById(id); LocationDeleteViewModel locationDeleteViewModel = new LocationDeleteViewModel() { Description = location.SZ_DESCRIPTION, EffectiveDate = location.DT_EFFECTIVE == null ? "" : location.DT_EFFECTIVE.Value.ToShortDateString(), ExpiredDate = location.DT_EXPIRED == null ? "" : location.DT_EXPIRED.Value.ToShortDateString(), LocationID = location.N_LOCATION_SYSID, Message = "", SelectedWaterBody = Convert.ToInt32(location.N_WATER_BODY_SYSID), SelectedWaterShed = Convert.ToInt32(location.N_LOCATION_TYPE_SYSID), ShowMessage = false, Station = location.SZ_LABEL, XCoordinate = location.N_GIS_X.ToString(), YCoordinate = location.N_GIS_Y.ToString(), WaterBody = _waterBodyRepo.GetWaterBodyByID(Convert.ToInt32(location.N_WATER_BODY_SYSID)), WaterShed = _waterShedRepo.GetWaterShedDescriptionByID(Convert.ToInt32(location.N_LOCATION_TYPE_SYSID)), OrderUpDown = location.SZ_STREAM_NUMBER, SearchText = SearchText }; return(View(locationDeleteViewModel)); } catch (Exception ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: LocationController.DeleteLoc_GET\n\nError: " + ex.Message; } else { ViewBag.Message = "Function: LocationController.DeleteLoc_GET\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message); }; Session["ErrorMessage"] = ViewBag.Message; return(RedirectToAction("InternalServerError", "Error")); }; }
public IActionResult DeleteLocation(Guid VenueId) { int?UKPRN = Session.GetInt32("UKPRN"); if (!UKPRN.HasValue) { return(RedirectToAction("Index", "Home", new { errmsg = "Please select a Provider." })); } var venueResult = _venueService .GetVenueByIdAsync(new GetVenueByIdCriteria(VenueId.ToString())).Result .Value; LocationDeleteViewModel locationDeleteViewModel = new LocationDeleteViewModel(); locationDeleteViewModel.VenueId = VenueId; locationDeleteViewModel.VenueName = venueResult.VenueName; locationDeleteViewModel.PostCode = venueResult.PostCode; locationDeleteViewModel.AddressLine1 = venueResult.Address1; return(View("../Venues/locationdelete/index", locationDeleteViewModel)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } LocationDeleteVM = await _context.Location.Select(l => new LocationDeleteViewModel() { LocationID = l.LocationID, LocationCode = l.LocationCode, DivisionName = l.Division.DivisionName, StateProvince = l.Address.StateProvince, Country = l.Address.Country }).FirstOrDefaultAsync(l => l.LocationID == id); if (LocationDeleteVM == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> Remove(LocationDeleteViewModel locationToDelete) { await this.locationsService.DeleteByIdAsync(locationToDelete.Id); return(this.RedirectToAction("All")); }