public ActionResult ConfirmDelete(int PrimaryID)
        {
            Tbl_FMOfficeType officetype = (from a in BOSSDB.Tbl_FMOfficeType where a.OfficeTypeID == PrimaryID select a).FirstOrDefault();

            BOSSDB.Tbl_FMOfficeType.Remove(officetype);
            BOSSDB.SaveChanges();

            var result = "";

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult DeleteOfficeType(int PrimaryID)
        {
            Tbl_FMOfficeType     officetype = (from a in BOSSDB.Tbl_FMOfficeType where a.OfficeTypeID == PrimaryID select a).FirstOrDefault();
            Tbl_FMRes_Department dept       = (from e in BOSSDB.Tbl_FMRes_Department where e.OfficeTypeID == PrimaryID select e).FirstOrDefault();
            Tbl_FMRes_Function   func       = (from e in BOSSDB.Tbl_FMRes_Function where e.OfficeTypeID == PrimaryID select e).FirstOrDefault();
            var confirmDelete = "";

            if (officetype != null)
            {
                if (dept != null || func != null)
                {
                    confirmDelete = "restricted";
                }
                else
                {
                    confirmDelete = "false";
                }
            }
            var result = new { confirmDelete = confirmDelete };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SaveOfficeType(OfficeTypeModel model)
        {
            var isExist = "";

            if (ModelState.IsValid)
            {
                var offtypetitle = model.OfficeTypeList.OfficeTypeTitle;
                offtypetitle = Regex.Replace(offtypetitle, @"\s\s+", "");
                offtypetitle = Regex.Replace(offtypetitle, @"^\s+", "");
                offtypetitle = Regex.Replace(offtypetitle, @"\s+$", "");
                offtypetitle = new CultureInfo("en-US").TextInfo.ToTitleCase(offtypetitle);
                Tbl_FMOfficeType checkofficetype = (from a in BOSSDB.Tbl_FMOfficeType where (a.OfficeTypeTitle == offtypetitle || a.OfficeTypeCode == model.OfficeTypeList.OfficeTypeCode) select a).FirstOrDefault();

                if (model.ActionID == 1)
                {
                    if (checkofficetype == null)
                    {
                        Tbl_FMOfficeType OfficeTypeTbl = new Tbl_FMOfficeType();
                        OfficeTypeTbl.OfficeTypeTitle = GlobalFunction.ReturnEmptyString(model.OfficeTypeList.OfficeTypeTitle);
                        OfficeTypeTbl.OfficeTypeCode  = GlobalFunction.ReturnEmptyString(model.OfficeTypeList.OfficeTypeCode);

                        BOSSDB.Tbl_FMOfficeType.Add(OfficeTypeTbl);
                        BOSSDB.SaveChanges();
                        isExist = "false";
                    }
                    else if (checkofficetype != null)
                    {
                        isExist = "true";
                    }
                }
                else if (model.ActionID == 2)
                {
                    Tbl_FMOfficeType        officetype  = (from e in BOSSDB.Tbl_FMOfficeType where e.OfficeTypeID == model.OfficeTypeList.OfficeTypeID select e).FirstOrDefault();
                    List <Tbl_FMOfficeType> officeTitle = (from e in BOSSDB.Tbl_FMOfficeType where e.OfficeTypeTitle == offtypetitle select e).ToList();
                    List <Tbl_FMOfficeType> officeCode  = (from e in BOSSDB.Tbl_FMOfficeType where e.OfficeTypeCode == model.OfficeTypeList.OfficeTypeCode select e).ToList();

                    if (checkofficetype != null)
                    {
                        if (officetype.OfficeTypeTitle == offtypetitle && officetype.OfficeTypeCode == model.OfficeTypeList.OfficeTypeCode) //walang binago
                        {
                            officetype.OfficeTypeTitle = offtypetitle;
                            officetype.OfficeTypeCode  = model.OfficeTypeList.OfficeTypeCode;
                            BOSSDB.Entry(officetype);
                            BOSSDB.SaveChanges();
                            isExist = "justUpdate";
                        }
                        else
                        {
                            if (officetype.OfficeTypeTitle != offtypetitle && officeTitle.Count >= 1 || officetype.OfficeTypeCode != model.OfficeTypeList.OfficeTypeCode && officeCode.Count >= 1)
                            {
                                isExist = "true";
                            }
                            else
                            {
                                officetype.OfficeTypeTitle = offtypetitle;
                                officetype.OfficeTypeCode  = model.OfficeTypeList.OfficeTypeCode;
                                BOSSDB.Entry(officetype);
                                BOSSDB.SaveChanges();
                                isExist = "justUpdate";
                            }
                        }
                    }
                    else if (checkofficetype == null)
                    {
                        officetype.OfficeTypeTitle = offtypetitle;
                        officetype.OfficeTypeCode  = model.OfficeTypeList.OfficeTypeCode;
                        BOSSDB.Entry(officetype);
                        BOSSDB.SaveChanges();
                        isExist = "justUpdate";
                    }
                }
            }
            return(new JsonResult()
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new { isExist = isExist }
            });
        }