コード例 #1
0
        /// <summary>
        /// API for creating a class
        /// </summary>
        /// <param name="classInstance">Data to be saved for a class.</param>
        /// <returns>A JSON response that contains a boolean of Success.</returns>
        public JsonResult CreateClass(QFClass classInstance)
        {
            if (ModelState.IsValid)
            {
                clientPortalInfo.Classes.Add(classInstance);
                clientPortalInfo.SaveChanges();
                return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
            }

            return Json(new { Success = false }, JsonRequestBehavior.AllowGet);
        }
コード例 #2
0
        /// <summary>
        /// API for updating a class
        /// </summary>
        /// <param name="classInstance">Data to be saved for a class.</param>
        /// <returns>A JSON response that contains a boolean of Success.</returns>
        public JsonResult UpdateClass(QFClass classInstance)
        {
            if (ModelState.IsValid)
            {
                var classToUpdate = clientPortalInfo.Classes.Where(item => item.ID == classInstance.ID).FirstOrDefault();

                if (classToUpdate != null)
                {
                    classToUpdate = classInstance;
                    clientPortalInfo.SaveChanges();
                    return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
                }
            }

            return Json(new { Success = false }, JsonRequestBehavior.AllowGet);
        }