public ActionResult DeleteSector(int PrimaryID) { Tbl_FMSector_Sector sector = (from a in BOSSDB.Tbl_FMSector_Sector where a.SectorID == PrimaryID select a).FirstOrDefault(); Tbl_FMSector_SubSector subSector = (from a in BOSSDB.Tbl_FMSector_SubSector where a.SectorID == PrimaryID select a).FirstOrDefault(); Tbl_FMRes_Department dept = (from e in BOSSDB.Tbl_FMRes_Department where e.SectorID == PrimaryID select e).FirstOrDefault(); Tbl_FMRes_Function func = (from e in BOSSDB.Tbl_FMRes_Function where e.SectorID == PrimaryID select e).FirstOrDefault(); var confirmDelete = ""; if (sector != null) { if (dept != null || func != null) { confirmDelete = "restricted"; } else if (subSector != null) { confirmDelete = "true"; } else { confirmDelete = "false"; } } var result = new { confirmDelete = confirmDelete }; return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult ConfirmDelete(int PrimaryID) { Tbl_FMSector_Sector sector = (from a in BOSSDB.Tbl_FMSector_Sector where a.SectorID == PrimaryID select a).FirstOrDefault(); BOSSDB.Tbl_FMSector_Sector.Remove(sector); BOSSDB.SaveChanges(); var result = ""; return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult SaveSector(SectorModel model) { var isExist = ""; if (ModelState.IsValid) { var SectorTitle = model.SectorList.SectorTitle; SectorTitle = new CultureInfo("en-US").TextInfo.ToTitleCase(SectorTitle); Tbl_FMSector_Sector checkSector = (from a in BOSSDB.Tbl_FMSector_Sector where (a.SectorTitle == SectorTitle || a.SectorCode == model.SectorList.SectorCode) select a).FirstOrDefault(); if (model.ActionID == 1) { if (checkSector == null) { Tbl_FMSector_Sector Sector = new Tbl_FMSector_Sector(); Sector.SectorTitle = SectorTitle; Sector.SectorCode = model.SectorList.SectorCode; BOSSDB.Tbl_FMSector_Sector.Add(Sector); BOSSDB.SaveChanges(); isExist = "false"; } else if (checkSector != null) { isExist = "true"; } } else if (model.ActionID == 2) { Tbl_FMSector_Sector Sector = (from a in BOSSDB.Tbl_FMSector_Sector where a.SectorID == model.SectorList.SectorID select a).FirstOrDefault(); List <Tbl_FMSector_Sector> sectorTitlelist = (from e in BOSSDB.Tbl_FMSector_Sector where e.SectorTitle == SectorTitle select e).ToList(); List <Tbl_FMSector_Sector> sectorCode = (from e in BOSSDB.Tbl_FMSector_Sector where e.SectorCode == model.SectorList.SectorCode select e).ToList(); if (checkSector != null) { if (Sector.SectorTitle == SectorTitle && Sector.SectorCode == model.SectorList.SectorCode) //walang binago { Sector.SectorTitle = SectorTitle; Sector.SectorCode = model.SectorList.SectorCode; BOSSDB.Entry(Sector); BOSSDB.SaveChanges(); isExist = "justUpdate"; } else { if (Sector.SectorTitle != SectorTitle && sectorTitlelist.Count >= 1 || Sector.SectorCode != model.SectorList.SectorCode && sectorCode.Count >= 1) { isExist = "true"; } else { Sector.SectorTitle = SectorTitle; Sector.SectorCode = model.SectorList.SectorCode; BOSSDB.Entry(Sector); BOSSDB.SaveChanges(); isExist = "justUpdate"; } } } else if (checkSector == null) { Sector.SectorTitle = SectorTitle; Sector.SectorCode = model.SectorList.SectorCode; BOSSDB.Entry(Sector); BOSSDB.SaveChanges(); isExist = "justUpdate"; } } } return(new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { isExist = isExist } }); }