コード例 #1
0
        // POST: OfficeFacilities/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        public JsonResult CreateOfficeFacility(OfficeFacility officeFacility)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int totalExistRows = db.OfficeFacilities.Where(x => x.OfficeFacilityName.Equals(officeFacility.OfficeFacilityName)).Count();
                    if (totalExistRows > 0)
                    {
                        return(Json(new { StatusCode = HttpStatusCode.Found, StatusMessage = "Office Facility already present" }, JsonRequestBehavior.AllowGet));
                    }
                    officeFacility.CreatedBy   = (Session["User"] as SessionEntity).UserID;
                    officeFacility.CreatedDate = DateTime.Now;
                    db.OfficeFacilities.Add(officeFacility);
                    db.SaveChanges();
                    return(Json(new { StatusCode = HttpStatusCode.Created, StatusMessage = "Office Facility Saved Successfully" }, JsonRequestBehavior.AllowGet));
                }
                ViewBag.CreatedBy = new SelectList(db.Users, "UserID", "FirstName", officeFacility.CreatedBy);
                ViewBag.OfficeID  = new SelectList(db.Offices, "OfficeID", "OfficeName", officeFacility.OfficeID);
                ViewBag.UpdatedBy = new SelectList(db.Users, "UserID", "FirstName", officeFacility.UpdatedBy);
            }
            catch (Exception e)
            {
                return(Json(new { StatusCode = HttpStatusCode.MethodNotAllowed, StatusMessage = e.Message }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new { StatusCode = HttpStatusCode.MethodNotAllowed, StatusMessage = "Please enter required fields" }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        // GET: OfficeFacilities/Details/5
        public ActionResult Details(int?id)
        {
            OfficeFacility officeFacility = db.OfficeFacilities.Find(id);

            if (officeFacility == null)
            {
                return(Json(new { StatusCode = HttpStatusCode.NoContent, StatusMessage = "Office Facility not found" }, JsonRequestBehavior.AllowGet));
            }
            return(PartialView(officeFacility));
        }
コード例 #3
0
        // GET: OfficeFacilities/Edit/5
        public ActionResult Edit(int?id)
        {
            OfficeFacility officeFacility = db.OfficeFacilities.Find(id);

            if (officeFacility == null)
            {
                return(Json(new { StatusCode = HttpStatusCode.NoContent, StatusMessage = "Office Facility not found" }, JsonRequestBehavior.AllowGet));
            }
            ViewBag.CreatedBy = new SelectList(db.Users, "UserID", "FirstName", officeFacility.CreatedBy);
            ViewBag.OfficeID  = new SelectList(db.Offices, "OfficeID", "OfficeName", officeFacility.OfficeID);
            ViewBag.UpdatedBy = new SelectList(db.Users, "UserID", "FirstName", officeFacility.UpdatedBy);
            return(PartialView(officeFacility));
        }
コード例 #4
0
 // POST: OfficeFacilities/Delete/5
 public JsonResult DeleteConfirmed(int id)
 {
     try
     {
         OfficeFacility officeFacility = db.OfficeFacilities.Find(id);
         db.OfficeFacilities.Remove(officeFacility);
         db.SaveChanges();
         return(Json(new { StatusCode = HttpStatusCode.Created, StatusMessage = "Office Faclility Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         return(Json(new { StatusCode = HttpStatusCode.MethodNotAllowed, StatusMessage = e.Message }, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #5
0
 // POST: OfficeFacilities/Edit/5
 // To protect from overposting attacks, please enable the specific properties you want to bind to, for
 // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
 public JsonResult UpdateOfficeFacility(OfficeFacility officeFacility)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(officeFacility).State = EntityState.Modified;
             officeFacility.UpdatedBy       = (Session["User"] as SessionEntity).UserID;
             officeFacility.UpdatedDate     = DateTime.Now;
             db.SaveChanges();
             return(Json(new { StatusCode = HttpStatusCode.Created, StatusMessage = "Office Facility Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
         ViewBag.CreatedBy = new SelectList(db.Users, "UserID", "FirstName", officeFacility.CreatedBy);
         ViewBag.OfficeID  = new SelectList(db.Offices, "OfficeID", "OfficeName", officeFacility.OfficeID);
         ViewBag.UpdatedBy = new SelectList(db.Users, "UserID", "FirstName", officeFacility.UpdatedBy);
     }
     catch (Exception e)
     {
         return(Json(new { StatusCode = HttpStatusCode.MethodNotAllowed, StatusMessage = e.Message }, JsonRequestBehavior.AllowGet));
     }
     return(Json(new { StatusCode = HttpStatusCode.MethodNotAllowed, StatusMessage = "Please enter required fields" }, JsonRequestBehavior.AllowGet));
 }