public JsonResult DeleteCourse(int Id)
        {
            try
            {
                db = new CourseDataContext();
                if (Id > 0)
                {
                    SITSPL_tblCourse course = db.SITSPL_tblCourses.Where(x => x.CourseId == Id).FirstOrDefault();
                    if (course != null)
                    {
                        db.SITSPL_tblCourses.DeleteOnSubmit(course);
                        db.SubmitChanges();
                        return(Json(Id.ToString(), JsonRequestBehavior.AllowGet));
                    }
                }

                return(Json("", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    message = new JavaScriptSerializer().Serialize(ex.Message.ToString());
                string str     = ex.Message;
                string err     = str.Substring(0, 61);
                if (err == "The DELETE statement conflicted with the REFERENCE constraint")
                {
                    return(Json("strcoursedepend", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(ex.Message, JsonRequestBehavior.AllowGet));
                }
                //  return Json(ex.Message, JsonRequestBehavior.AllowGet);
            }
        }
        public JsonResult UpdateCourse(int intId, string strCourse)
        {
            try
            {
                db = new CourseDataContext();
                bool isResult = false;
                //   string Cour = Course.Trim();
                if (intId > 0)
                {
                    SITSPL_tblCourse course = db.SITSPL_tblCourses.Where(x => x.CourseId == intId).SingleOrDefault();
                    var data = db.SITSPL_tblCourses.Select(x => x.CourseName).ToList();

                    var alldata = db.SITSPL_tblCourses.Where(x => x.CourseId == intId).Select(x => new
                    {
                        x.CourseId,
                        x.CourseName
                    }).FirstOrDefault();

                    if (data.Contains(strCourse.Trim(), StringComparer.OrdinalIgnoreCase))
                    {
                        if (intId == alldata.CourseId && strCourse.ToLower() == alldata.CourseName.ToLower())
                        {
                            course.CourseName = strCourse;
                            db.SubmitChanges();
                            isResult = true;
                            return(Json(isResult, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            isResult = false;
                            return(Json(isResult, JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(strCourse.Trim()))
                        {
                            course.CourseName = strCourse;
                            db.SubmitChanges();
                            isResult = true;
                            return(Json(isResult, JsonRequestBehavior.AllowGet));
                        }
                    }
                }
                return(Json("", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
 public JsonResult CreateCourse(SITSPL_tblCourse objCourse)
 {
     try
     {
         db = new CourseDataContext();
         bool   result = false;
         string Cour   = objCourse.CourseName;
         var    data   = db.SITSPL_tblCourses.Select(x => new { x.CourseName }).ToList();
         var    Cours  = data.Select(x => x.CourseName);
         if (Cour != null && !Cours.Contains(Cour, StringComparer.OrdinalIgnoreCase))
         {
             objCourse.DateCreated   = DateTime.Now;
             objCourse.DatePublished = DateTime.Now;
             objCourse.IsPublished   = true;
             objCourse.CreatedBy     = "Admin";
             db.SITSPL_tblCourses.InsertOnSubmit(objCourse);
             db.SubmitChanges();
             result = true;
             return(Json(result, JsonRequestBehavior.AllowGet));
         }
         else if (Cour != null && Cours.Contains(Cour, StringComparer.OrdinalIgnoreCase))
         {
             ViewBag.InsertMessage = "Course already exists";
             result = false;
             return(Json(result, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json("empty", JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(ex.Message, JsonRequestBehavior.AllowGet));
     }
 }