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 addShortCourseFeature(int courseID, string callback, string text, string heading, HttpPostedFileWrapper galleryImage, string languageCode = "en") { ajaxReturnData data = new ajaxReturnData(); ShortCourse course = new ShortCourse(); try { using (ApplicationDbContext DB = new ApplicationDbContext()) { //course = DB.shortCourses.Where(sc => sc.id == courseID).FirstOrDefault(); //ImageGallery gallery; //GalleryImage img = new GalleryImage(); //if (DB.gallerys.Where(g => g.id == course.featureGalleryID).Any()) //{ // gallery = DB.gallerys.Where(g => g.id == course.featureGalleryID).FirstOrDefault(); //} //else //{ // gallery = new ImageGallery(); // DB.gallerys.Add(gallery); // DB.SaveChanges(); // gallery.addTitle(DB, course.url + " features"); //} //course.featureGalleryID = gallery.id; //if (galleryImage != null && galleryImage.ContentLength > 0) //{ // string path = "/content/images/uploads/galleries/" + gallery.id; // bool exists = Directory.Exists(Server.MapPath(path)); // if (!exists) // { // Directory.CreateDirectory(Server.MapPath(path)); // } // img.galleryID = gallery.id; // DB.galleryImages.Add(img); // DB.SaveChanges(); // path = path + "/" + img.id + Path.GetExtension(galleryImage.FileName); // galleryImage.SaveAs(Server.MapPath(path)); // img.image = path; // DB.SaveChanges(); //} //DB.SaveChanges(); //img.addText(DB, text); //img.addTitle(DB, heading); } if (string.IsNullOrEmpty(callback)) { data.statusCode = (int)statusCodes.success; } else { data.statusCode = (int)statusCodes.successRun; data.callback = callback; } data.message = "short course feature added"; return Json(data); } catch (Exception ex) { data.statusCode = (int)statusCodes.fail; data.message = "Failed to add short course feature; " + 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); } }