public ActionResult addContent (Content content) { ajaxReturnData data = new ajaxReturnData(); using (ApplicationDbContext db = new ApplicationDbContext()) { try { db.Content.Add(content); db.SaveChanges(); data.statusCode = (int)statusCodes.successRun; data.callback = "getContentList"; data.message = "Content section '"+content.name+"' added"; } catch (Exception ex) { data.statusCode = (int)statusCodes.fail; data.message = "Error: Content not added; " + ex.Message; } } return Json(data); }
protected bool addContent(ApplicationDbContext DB, string name, string body) { if(content.Count < 1) { loadContent(DB); } if (content.Where(c => c.name == name).Any()) { Content con = content.Where(c => c.name == name).FirstOrDefault(); if (con.contentCollection.Where(c => c.code == languageCode).Any()) { ContentBody cb = con.contentCollection.Where(c => c.code == languageCode).FirstOrDefault(); cb.body = body; cb.lastModified = DateTime.Now; cb.lastModifiedByID = HttpContext.Current.User.Identity.GetUserId(); DB.SaveChanges(); } else { ContentBody cb = new ContentBody(); cb.contentID = con.contentID; cb.code = languageCode; cb.lastModified = DateTime.Now; cb.lastModifiedByID = HttpContext.Current.User.Identity.GetUserId(); cb.body = body; con.contentCollection.Add(cb); DB.SaveChanges(); } } else { Content con = new Content(); con.name = name; con.contentCollection = new List<ContentBody>(); ContentBody cb = new ContentBody(); cb.code = languageCode; cb.lastModified = DateTime.Now; cb.lastModifiedByID = HttpContext.Current.User.Identity.GetUserId(); cb.body = body; con.contentCollection.Add(cb); content.Add(con); DB.SaveChanges(); } return true; }
protected bool addContent(ApplicationDbContext DB, string name, string body) { if (DB.Content.Where(c => c.planFeatureID == id && c.name == name).Any()) { Content c = DB.Content.Where(c2 => c2.planFeatureID == id && c2.name == name).FirstOrDefault(); if (DB.ContentBody.Where(cb2 => cb2.contentID == c.contentID && cb2.code == languageCode).Any()) { ContentBody cb3 = DB.ContentBody.Where(cb2 => cb2.contentID == c.contentID && cb2.code == languageCode).FirstOrDefault(); cb3.body = body; cb3.lastModified = DateTime.Now; cb3.lastModifiedByID = HttpContext.Current.User.Identity.GetUserId(); DB.SaveChanges(); } else { ContentBody cb3 = new ContentBody(); cb3.contentID = c.contentID; cb3.code = languageCode; cb3.lastModified = DateTime.Now; cb3.lastModifiedByID = HttpContext.Current.User.Identity.GetUserId(); cb3.body = body; DB.ContentBody.Add(cb3); DB.SaveChanges(); } } else { Content content = new Content(); content.planFeatureID = id; content.name = name; DB.Content.Add(content); DB.SaveChanges(); ContentBody cb = new ContentBody(); cb.contentID = content.contentID; cb.code = languageCode; cb.lastModified = DateTime.Now; cb.lastModifiedByID = HttpContext.Current.User.Identity.GetUserId(); cb.body = body; DB.ContentBody.Add(cb); DB.SaveChanges(); } return true; }
public ActionResult editContent(Content content, string callback) { ajaxReturnData data = new ajaxReturnData(); using (ApplicationDbContext db = new ApplicationDbContext()) { try { db.Entry(content).State = EntityState.Modified; db.SaveChanges(); if (string.IsNullOrEmpty(callback)) { data.statusCode = (int)statusCodes.success; } else { data.statusCode = (int)statusCodes.successRun; data.callback = callback; } data.message = "Content section '" + content.name + "' updated"; } catch (Exception ex) { data.statusCode = (int)statusCodes.fail; data.message = "Error: Content not updated; " + ex.Message; } } return Json(data); }
public ActionResult addLocation(Location location, string callback, string description, string city, HttpPostedFileWrapper image) { ajaxReturnData data = new ajaxReturnData(); try { using (ApplicationDbContext DB = new ApplicationDbContext()) { DB.Locations.Add(location); DB.SaveChanges(); //add name field //Content content = new Content(); //content.name = "name"; //content.locationID = location.id; //DB.Content.Add(content); //DB.SaveChanges(); //ContentBody cb = new ContentBody(); //cb.contentID = content.contentID; //cb.code = "en"; //cb.body = name; //cb.lastModifiedByID = User.Identity.GetUserId(); //cb.lastModified = DateTime.Now; //DB.ContentBody.Add(cb); //DB.SaveChanges(); //add description field Content content = new Content(); content.name = "description"; content.locationID = location.id; DB.Content.Add(content); DB.SaveChanges(); ContentBody cb = new ContentBody(); cb.contentID = content.contentID; cb.code = "en"; cb.body = description; cb.lastModifiedByID = User.Identity.GetUserId(); cb.lastModified = DateTime.Now; DB.ContentBody.Add(cb); DB.SaveChanges(); ////add city field //content = new Content(); //content.name = "city"; //content.locationID = location.id; //DB.Content.Add(content); //DB.SaveChanges(); //cb = new ContentBody(); //cb.contentID = content.contentID; //cb.code = "en"; //cb.body = city; //cb.lastModifiedByID = User.Identity.GetUserId(); //cb.lastModified = DateTime.Now; //DB.ContentBody.Add(cb); //DB.SaveChanges(); if (image != null && image.ContentLength > 0) { string path = "/content/images/uploads/locations/" + location.id; bool exists = Directory.Exists(Server.MapPath(path)); if (!exists) { Directory.CreateDirectory(Server.MapPath(path)); } path = path + "/locationImage" + Path.GetExtension(image.FileName); image.SaveAs(Server.MapPath(path)); location.image = path; DB.Entry(location).Property(l => l.image).IsModified = true; } //int contentID; //contentID = DB.Content.Where(c => c.locationID == location.id && c.name == "name").FirstOrDefault().contentID; //ContentBody cb = DB.ContentBody.Where(c => c.contentID == contentID && c.code == "en").FirstOrDefault(); //cb.body = name; DB.SaveChanges(); } if (string.IsNullOrEmpty(callback)) { data.statusCode = (int)statusCodes.success; } else { data.statusCode = (int)statusCodes.successRun; data.callback = callback; } data.message = "location added"; return Json(data); } catch (Exception ex) { data.statusCode = (int)statusCodes.fail; data.message = "Failed to add location; " + ex.Message; return Json(data); } }
public ActionResult deleteContent(int contentID, string callback) { ajaxReturnData data = new ajaxReturnData(); using (ApplicationDbContext DB = new ApplicationDbContext()) { try { Content c = new Content(); c.contentID = contentID; DB.Content.Attach(c); DB.Entry(c).State = EntityState.Deleted; DB.SaveChanges(); data.message = "Content deleted"; if (string.IsNullOrEmpty(callback)) { data.statusCode = (int)statusCodes.success; } else { data.statusCode = (int)statusCodes.successRun; data.callback = callback; } } catch (Exception ex) { data.statusCode = (int)statusCodes.fail; data.message = "Error: " + ex.Message; } } return Json(data); }