/// <summary> /// to get location id for selridge ang base /// </summary> public int GetSelfridgeLocationID() { //find location for selfridge ang base from location table. if exists - use it, else - create new record using (Entities db = new Entities()) { int selfridgeLocationID = db.REF_LOCATION_TB.Where(u => u.SZ_DESCRIPTION.ToUpper().Contains("SELFRIDGE")).Select(u => u.N_LOCATION_SYSID).FirstOrDefault(); if (selfridgeLocationID == 0) { REF_LOCATION_TB location = new REF_LOCATION_TB() { B_INACTIVE = false, DT_MODIFIED = DateTime.UtcNow, DT_ENTERED = DateTime.UtcNow, SZ_DESCRIPTION = "Selfridge", SZ_ENTERED_BY = SessionHelper.UserName, SZ_LABEL = "-1", SZ_MODIFIED_BY = SessionHelper.UserName }; db.REF_LOCATION_TB.Add(location); db.SaveChanges(); return(db.REF_LOCATION_TB.Where(u => u.SZ_DESCRIPTION.ToUpper().Contains("SELFRIDGE")).Select(u => u.N_LOCATION_SYSID).FirstOrDefault()); } else { return(selfridgeLocationID); } } }
public ActionResult Create(int ID, string SearchText, int?LocationGroupID) { try { REF_LOCATION_TB location = _uow.Repository <REF_LOCATION_TB>().GetById(ID); LocationCreateGroupViewModel model = new LocationCreateGroupViewModel() { ID = ID, LocationDescription = location.SZ_LABEL + " - " + location.SZ_DESCRIPTION, LocationGroups = (List <SelectListItem>)_locationRepo.GetLocationGroupsSelectListByLocationID(ID), SelectedLocationGroup = 0, SearchText = SearchText }; return(View(model)); } catch (Exception ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: LocationController.Create_GET\n\nError: " + ex.Message; } else { ViewBag.Message = "Function: LocationController.Create_GET\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message); }; Session["ErrorMessage"] = ViewBag.Message; return(RedirectToAction("InternalServerError", "Error")); }; }
public ActionResult Edit(int ID, string SearchText) { try { var locationEditViewModel = new LocationEditViewModel(); if (ID > 0) { REF_LOCATION_TB location = _uow.Repository <REF_LOCATION_TB>().GetById(ID); locationEditViewModel.Description = location.SZ_DESCRIPTION; locationEditViewModel.EffectiveDate = location.DT_EFFECTIVE == null ? "" : location.DT_EFFECTIVE.Value.ToShortDateString(); locationEditViewModel.ExpiredDate = location.DT_EXPIRED == null ? "" : location.DT_EXPIRED.Value.ToShortDateString(); locationEditViewModel.LocationID = ID; locationEditViewModel.SearchText = SearchText; locationEditViewModel.SelectedWaterBody = Convert.ToInt32(location.N_WATER_BODY_SYSID); locationEditViewModel.SelectedWaterShed = Convert.ToInt32(location.N_LOCATION_TYPE_SYSID); locationEditViewModel.Station = location.SZ_LABEL; locationEditViewModel.WaterBodies = (List <SelectListItem>)_waterBodyRepo.GetWaterBodies(); locationEditViewModel.WaterSheds = (List <SelectListItem>)_waterShedRepo.GetWaterSheds(); locationEditViewModel.XCoordinate = Convert.ToDouble(location.N_GIS_X); locationEditViewModel.YCoordinate = Convert.ToDouble(location.N_GIS_Y); locationEditViewModel.OrderUpDown = location.SZ_STREAM_NUMBER; } else { locationEditViewModel.Description = ""; locationEditViewModel.EffectiveDate = ""; locationEditViewModel.ExpiredDate = ""; locationEditViewModel.LocationID = ID; locationEditViewModel.SearchText = SearchText; locationEditViewModel.SelectedWaterBody = 0; locationEditViewModel.SelectedWaterShed = 0; locationEditViewModel.Station = ""; locationEditViewModel.WaterBodies = (List <SelectListItem>)_waterBodyRepo.GetWaterBodies(); locationEditViewModel.WaterSheds = (List <SelectListItem>)_waterShedRepo.GetWaterSheds(); locationEditViewModel.XCoordinate = 0; locationEditViewModel.YCoordinate = 0; locationEditViewModel.OrderUpDown = ""; } return(View("Edit", locationEditViewModel)); } catch (Exception ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: LocationController.Edit_GET\n\nError: " + ex.Message; } else { ViewBag.Message = "Function: LocationController.Edit_GET\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message); }; Session["ErrorMessage"] = ViewBag.Message; return(RedirectToAction("InternalServerError", "Error")); }; }
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 ActionResult Details(int ID, string SearchText, int?LocationGroupID) { try { REF_LOCATION_TB location = _uow.Repository <REF_LOCATION_TB>().GetById(ID); LocationDetailsViewModel model = new LocationDetailsViewModel() { Description = location.SZ_DESCRIPTION, EffectiveDate = location.DT_EFFECTIVE == null ? "" : location.DT_EFFECTIVE.Value.ToShortDateString(), ExpiredDate = location.DT_EXPIRED == null ? "" : location.DT_EXPIRED.Value.ToShortDateString(), LocationGroupID = Convert.ToInt32(LocationGroupID), LocationID = ID, SearchText = SearchText, Station = location.SZ_LABEL, XCoordinate = location.N_GIS_X.ToString(), YCoordinate = location.N_GIS_Y.ToString(), OrderUpDown = location.SZ_STREAM_NUMBER }; return(View(model)); } catch (Exception ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: LocationController.Details_GET\n\nError: " + ex.Message; } else { ViewBag.Message = "Function: LocationController.Details_GET\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message); }; Session["ErrorMessage"] = ViewBag.Message; return(RedirectToAction("InternalServerError", "Error")); }; }
public ActionResult Edit(LocationEditViewModel Model) { bool saveFailed; do { saveFailed = false; try { if (ModelState["XCoordinate"].Errors.Count > 0) { string code = ModelState["XCoordinate"].Value.AttemptedValue.ToString(); string[] parts = code.Split(','); string entry = parts[0]; string response = "The value: '" + entry + "' is not valid. Please enter a numeric value."; ModelState.Remove("XCoordinate"); ModelState.AddModelError("XCoordinate", response); } if (ModelState["YCoordinate"].Errors.Count > 0) { string code = ModelState["YCoordinate"].Value.AttemptedValue.ToString(); string[] parts = code.Split(','); string entry = parts[0]; string response = "The value: '" + entry + "' is not valid. Please enter a numeric value."; ModelState.Remove("YCoordinate"); ModelState.AddModelError("YCoordinate", response); } if (ModelState["SelectedWaterBody"].Errors.Count > 0) { Model.SelectedWaterBody = null; ModelState.Remove("SelectedWaterBody"); } if (ModelState["SelectedWaterShed"].Errors.Count > 0) { Model.SelectedWaterShed = null; ModelState.Remove("SelectedWaterShed"); } if (ModelState.IsValid) { int id = 0; if (Model.LocationID == 0) //new { REF_LOCATION_TB location = new REF_LOCATION_TB() { B_INACTIVE = false, DT_EFFECTIVE = Model.EffectiveDate == "" ? (DateTime?)null : Convert.ToDateTime(Model.EffectiveDate), DT_ENTERED = DateTime.UtcNow, DT_EXPIRED = Model.ExpiredDate == "" ? (DateTime?)null : Convert.ToDateTime(Model.ExpiredDate), DT_MODIFIED = DateTime.UtcNow, N_GIS_X = Convert.ToDecimal(Model.XCoordinate), N_GIS_Y = Convert.ToDecimal(Model.YCoordinate), N_LOCATION_TYPE_SYSID = Model.SelectedWaterShed, N_WATER_BODY_SYSID = Model.SelectedWaterBody, SZ_DESCRIPTION = Model.Description, SZ_ENTERED_BY = _modifiedBy, SZ_LABEL = Model.Station, SZ_MODIFIED_BY = _modifiedBy, SZ_STREAM_NUMBER = Model.OrderUpDown }; _uow.Repository <REF_LOCATION_TB>().Add(location); _uow.SaveChanges(); DateTime effectiveDate = Convert.ToDateTime(Model.EffectiveDate); DateTime expiredDate = Convert.ToDateTime(Model.ExpiredDate); Decimal xCoord = Convert.ToDecimal(Model.XCoordinate); Decimal yCoord = Convert.ToDecimal(Model.YCoordinate); REF_LOCATION_TB locationFound = _uow.Repository <REF_LOCATION_TB>().Find(u => u.SZ_ENTERED_BY == _modifiedBy && u.SZ_MODIFIED_BY == _modifiedBy && u.DT_EFFECTIVE == effectiveDate && u.DT_EXPIRED == expiredDate && u.N_GIS_X == xCoord && u.N_GIS_Y == yCoord && u.N_LOCATION_TYPE_SYSID == Model.SelectedWaterShed && u.N_WATER_BODY_SYSID == Model.SelectedWaterBody && u.SZ_DESCRIPTION == Model.Description && u.SZ_LABEL == Model.Station && u.SZ_STREAM_NUMBER == Model.OrderUpDown).FirstOrDefault(); id = locationFound.N_LOCATION_SYSID; } else //edit { REF_LOCATION_TB location = _uow.Repository <REF_LOCATION_TB>().GetById(Model.LocationID); location.DT_EFFECTIVE = Convert.ToDateTime(Model.EffectiveDate); location.DT_EXPIRED = Convert.ToDateTime(Model.ExpiredDate); location.DT_MODIFIED = DateTime.UtcNow; location.N_GIS_X = Convert.ToDecimal(Model.XCoordinate); location.N_GIS_Y = Convert.ToDecimal(Model.YCoordinate); location.N_LOCATION_TYPE_SYSID = Model.SelectedWaterShed; location.N_WATER_BODY_SYSID = Model.SelectedWaterBody; location.SZ_DESCRIPTION = Model.Description; location.SZ_LABEL = Model.Station; location.SZ_STREAM_NUMBER = Model.OrderUpDown; _uow.Repository <REF_LOCATION_TB>().Update(location); _uow.SaveChanges(); id = Model.LocationID; } return(RedirectToAction("Index", new { ID = id, Search = Model.SearchText })); } Model.WaterBodies = (List <SelectListItem>)_waterBodyRepo.GetWaterBodies(); Model.WaterSheds = (List <SelectListItem>)_waterShedRepo.GetWaterSheds(); return(View(Model)); } catch (DbEntityValidationException ex) { StringBuilder sb = new StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation:\n\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } if (ex.InnerException == null) { ViewBag.Message = "Function: LocationController.Edit_POST\n\nError: " + ex.Message + "\n\n" + sb; } else { ViewBag.Message = "Function: LocationController.Edit_POST\n\nError: " + ex.Message + "\n\n" + sb + "\n\n" + ex.InnerException.Message; }; } catch (DbUpdateConcurrencyException ex) { saveFailed = true; var entry = ex.Entries.Single(); entry.OriginalValues.SetValues(entry.GetDatabaseValues()); } catch (DataException ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: LocationController.Edit_POST\n\nError: " + ex.Message + "\n\nBaseException: " + ex.GetBaseException().Message; } else { ViewBag.Message = "Function: LocationController.Edit_POST\n\nError: " + ex.Message + "\n\nBaseException: " + ex.GetBaseException().Message + "\n\nInnerException: " + ex.InnerException.Message; }; } catch (Exception ex) { if (ex.InnerException == null) { ViewBag.Message = "Function: LocationController.Edit_POST\n\nError: " + ex.Message; } else { ViewBag.Message = "Function: LocationController.Edit_POST\n\nError: " + ex.Message + "\n\nBaseException: " + ex.InnerException.Message; }; }; } while (saveFailed); Session["ErrorMessage"] = ViewBag.Message; return(RedirectToAction("InternalServerError", "Error")); }