public static string AddArea(string CityID, string AreaName) { // result 0 for not saved // result -1 for some internal error // result 1 or greater than 1 for successfuly saved string result = "0"; AreaDetail area = new AreaDetail(); try { area.CityID = Convert.ToInt32(CityID); area.Area = AreaName; area.IsActive = true; area.IsDeleted = false; Global.dc.AreaDetails.Add(area); int count = Global.dc.SaveChanges(); result = Convert.ToString(count); } catch (Exception) { result = "-1"; } return(result); }
public string DeleteCity(string ID) { string result = string.Empty; try { int CityID = Convert.ToInt32(ID); AreaDetail area = Global.dc.AreaDetails.FirstOrDefault(i => i.CityID == CityID && i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue)); if (area != null) { //City Is used in another result = "4"; } else { CityDetail city = Global.dc.CityDetails.FirstOrDefault(i => i.ID == CityID && i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue)); if (city != null) { city.IsDeleted = true; int count = Global.dc.SaveChanges(); result = Convert.ToString(count); } else { result = "3"; } } } catch (Exception) { result = "-1"; } return(result); }
public string DeleteArea(string ID) { string result = string.Empty; try { int AreaID = Convert.ToInt32(ID); //check for cascade delete in hoarding master var IsUsedInHoarding = Global.dc.SubAreaDetails.FirstOrDefault(i => i.IsActive == true && (!i.IsDeleted.HasValue || !i.IsDeleted.Value) && i.AreaID == AreaID); if (IsUsedInHoarding != null) { return("4"); } else { AreaDetail area = Global.dc.AreaDetails.FirstOrDefault(i => i.ID == AreaID && i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue)); if (area != null) { area.IsDeleted = true; int count = Global.dc.SaveChanges(); result = Convert.ToString(count); } else { result = "3"; } } } catch (Exception) { result = "-1"; } return(result); }
public string EditArea(string ID) { string result = string.Empty; Area data = new Area(); try { int AreaID = Convert.ToInt32(ID); AreaDetail area = Global.dc.AreaDetails.FirstOrDefault(i => i.ID == AreaID && i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue)); if (area != null) { data.ID = area.ID; data.AreaName = area.Area; data.CityID = area.CityID; data.CityName = area.CityDetail.CityName; result = new JavaScriptSerializer().Serialize(data); } else { result = "3"; } } catch (Exception) { result = "-1"; } return(result); }
public string AddArea(string CityID, string AreaName, string Operation, string ID) { // result 0 for not saved // result -1 for some internal error // result 1 or greater than 1 for successfuly saved string result = "0"; AreaDetail area = new AreaDetail(); try { if (Operation == "add") { var isAreaExist = Global.dc.AreaDetails.FirstOrDefault(i => i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue) && i.Area.Replace(" ", "").ToLower() == AreaName.Replace(" ", "").ToLower()); if (isAreaExist != null) { result = "2"; } else { area.CityID = Convert.ToInt32(CityID); area.Area = AreaName; area.IsActive = true; area.IsDeleted = false; Global.dc.AreaDetails.Add(area); int count = Global.dc.SaveChanges(); result = Convert.ToString(count); } } else if (Operation == "edit") { int AreaID = Convert.ToInt32(ID); var isAreaExist = Global.dc.AreaDetails.FirstOrDefault(i => i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue) && i.Area.Replace(" ", "").ToLower() == AreaName.Replace(" ", "").ToLower() && i.ID != AreaID); if (isAreaExist != null) { result = "2"; } else { area = Global.dc.AreaDetails.FirstOrDefault(i => i.IsActive == true && (!i.IsDeleted.Value || !i.IsDeleted.HasValue) && i.ID == AreaID); if (area != null) { area.CityID = Convert.ToInt32(CityID); area.Area = AreaName; area.IsActive = true; area.IsDeleted = false; int count = Global.dc.SaveChanges(); result = Convert.ToString(count); } else { result = "3"; } } } } catch (Exception) { result = "-1"; } return(result); }