public ActionResult addShortCourse(string callback, string url, string name) { ajaxReturnData data = new ajaxReturnData(); try { using (ApplicationDbContext DB = new ApplicationDbContext()) { if (DB.shortCourses.Where(s => s.url == url).Any()) { data.message = "School already be existing; No need to re-exist it"; data.statusCode = (int)statusCodes.fail; } else { ShortCourse sc = new ShortCourse(); sc.url = url; Faq faq = new Faq(); sc.faq = faq; DB.shortCourses.Add(sc); DB.SaveChanges(); sc.addContent(DB, "name", name); DB.SaveChanges(); } } if (string.IsNullOrEmpty(callback)) { data.statusCode = (int)statusCodes.success; } else { data.statusCode = (int)statusCodes.successRun; data.callback = callback; } data.message = "short course added"; return Json(data); } catch (Exception ex) { data.statusCode = (int)statusCodes.fail; data.message = "Failed to add short course; " + ex.Message; return Json(data); } }
public ActionResult editShortCourseGeneral(int id, int schoolID, string descriptionHeading, string bookNowLink, string dates, string video, string name, string url, HttpPostedFileWrapper descriptionImage, HttpPostedFileWrapper videoCover, string callback, string languageCode = "en") { ajaxReturnData data = new ajaxReturnData(); ShortCourse course = new ShortCourse(); try { using (ApplicationDbContext DB = new ApplicationDbContext()) { if (DB.shortCourses.Where(s => s.url == url && s.id != id).Any()) { data.message = "short course url is taken"; data.statusCode = (int)statusCodes.fail; } else { course = DB.shortCourses.Where(sc => sc.id == id).FirstOrDefault(); course.video = video; course.url = url; course.schoolID = schoolID; course.bookNowLink = bookNowLink; if (descriptionImage != null && descriptionImage.ContentLength > 0) { string path = "/content/images/uploads/shortCourses/" + course.id; bool exists = Directory.Exists(Server.MapPath(path)); if (!exists) { Directory.CreateDirectory(Server.MapPath(path)); } path = path + "/descriptionImage" + Path.GetExtension(descriptionImage.FileName); descriptionImage.SaveAs(Server.MapPath(path)); course.descriptionImage = path; DB.Entry(course).Property(l => l.descriptionImage).IsModified = true; } if (videoCover != null && videoCover.ContentLength > 0) { string path = "/content/images/uploads/shortCourses/" + course.id; bool exists = Directory.Exists(Server.MapPath(path)); if (!exists) { Directory.CreateDirectory(Server.MapPath(path)); } path = path + "/videoCover" + Path.GetExtension(videoCover.FileName); videoCover.SaveAs(Server.MapPath(path)); course.videoCover = path; DB.Entry(course).Property(l => l.videoCover).IsModified = true; } course.addContent(DB, "name", name); course.addContent(DB, "dates", dates); course.addContent(DB, "descriptionHeading", descriptionHeading); DB.SaveChanges(); } } if (string.IsNullOrEmpty(callback)) { data.statusCode = (int)statusCodes.success; } else { data.statusCode = (int)statusCodes.successRun; data.callback = callback; } data.message = "short course updated"; return Json(data); } catch (Exception ex) { data.statusCode = (int)statusCodes.fail; data.message = "Failed to update short course; " + ex.Message; return Json(data); } }