public ActionResult ContentDown(int id, int updateid) { //get the data var content = db.update_content.FirstOrDefault(x => x.ContentID == id); //(reverse the ordering , to sort in the right direction) var contents = db.update_content.Where(x => x.UpdateID == updateid).OrderBy("Order"); //search for the swappable content update_content othercontent = null; foreach (update_content updateContent in contents) { if (updateContent.ContentID == id) { break; } othercontent = updateContent; } //swap if (othercontent != null && othercontent.ContentID != content.ContentID) { int oldorder = content.Order; content.Order = othercontent.Order; othercontent.Order = oldorder; db.SaveChanges(); } return(RedirectToAction("Edit", "Update", new { id = updateid })); }
// // GET: /Admin/UpdateContents/Edit/5 public ActionResult Edit(int id) { update_content update_content = db.update_content.Single(u => u.ContentID == id); ViewBag.UpdateID = new SelectList(db.updates, "UpdateID", "Title", update_content.UpdateID); ViewBag.ContentTypeID = new SelectList(db.update_content_type, "ContentTypeID", "ContentTypeName", update_content.ContentTypeID); return(View(update_content)); }
public ActionResult DeleteConfirmed(int id) { update_content update_content = db.update_content.Single(u => u.ContentID == id); db.update_content.DeleteObject(update_content); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { update_content update_content = db.update_content.Single(u => u.ContentID == id); db.update_content.DeleteObject(update_content); db.SaveChanges(); return(RedirectToAction("Edit", "Projects", new { id = update_content.update.ProjectID }, "updates")); }
public ActionResult Edit(update_content update_content) { if (ModelState.IsValid) { db.update_content.Attach(update_content); db.ObjectStateManager.ChangeObjectState(update_content, EntityState.Modified); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UpdateID = new SelectList(db.updates, "UpdateID", "Title", update_content.UpdateID); ViewBag.ContentTypeID = new SelectList(db.update_content_type, "ContentTypeID", "ContentTypeName", update_content.ContentTypeID); return(View(update_content)); }
public ActionResult Create(update_content update_content) { if (ModelState.IsValid) { db.update_content.AddObject(update_content); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UpdateID = new SelectList(db.updates, "UpdateID", "Title", update_content.UpdateID); ViewBag.ContentTypeID = new SelectList(db.update_content_type, "ContentTypeID", "ContentTypeName", update_content.ContentTypeID); return(View(update_content)); }
public ActionResult ContentUp(int id, int updateid) { var ucontent = db.update_content.FirstOrDefault(x => x.ContentID == id); var update = db.updates.FirstOrDefault(x => x.UpdateID == ucontent.UpdateID); var project = db.projects.FirstOrDefault(x => x.ProjectID == update.ProjectID && x.UserID == CurrentUser.UserID); if (project == null) { return(RedirectToAction("Index", "Home")); } //get the data var content = db.update_content.FirstOrDefault(x => x.ContentID == id); var contents = db.update_content.Where(x => x.UpdateID == updateid).OrderByDescending("Order"); //search for the swappable content update_content othercontent = null; foreach (update_content updateContent in contents) { if (updateContent.ContentID == id) { break; } othercontent = updateContent; } //swap if (othercontent != null && othercontent.ContentID != content.ContentID) { int oldorder = content.Order; content.Order = othercontent.Order; othercontent.Order = oldorder; db.SaveChanges(); } return(RedirectToAction("Edit", "Update", new { id = updateid })); }
// // GET: /Admin/UpdateContents/Delete/5 public ActionResult Delete(int id) { update_content update_content = db.update_content.Single(u => u.ContentID == id); return(View(update_content)); }
// // GET: /Admin/UpdateContents/Details/5 public ViewResult Details(int id) { update_content update_content = db.update_content.Single(u => u.ContentID == id); return(View(update_content)); }
public ActionResult ContentEdit(update_content update_content, int ProjectID = 0) { //File Upload if (Request.Files != null && Request.Files.Count > 0) { foreach (string keyname in Request.Files) { HttpPostedFileBase file = Request.Files[keyname]; if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName)) { //file upload string ext = Path.GetExtension(file.FileName).ToLower(); if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".swf" && ext != ".fla") { ModelState.AddModelError(keyname, "Invalid file type"); return(RedirectToAction("Edit", "Update", new { id = update_content.UpdateID })); } try { if (ext == ".png" || ext == ".jpg" || ext == ".jpeg") { using (Image tmp = Image.FromStream(file.InputStream)) { //resize+crop int width = int.Parse(ConfigurationManager.AppSettings["Image_Update_Width"]); int height = int.Parse(ConfigurationManager.AppSettings["Image_Update_Height"]); string name = getTimestamp() + ".jpg"; string filepath = string.Format("projects/{0}/update_{1}/{2}", ProjectID, update_content.UpdateID, name); string address = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath; //send using (Image resized = tmp.GetResizedImage(width, height, true)) { var request = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath); using (MemoryStream buffer = new MemoryStream()) { resized.Save(buffer, ImageHelper.GetJpgEncoder(), ImageHelper.GetJpgEncoderParameters(80)); request.InputStream = buffer; AmazonS3Client s3Client = new AmazonS3Client(); s3Client.PutObject(request); } } ModelState.Remove(keyname); ModelState.Add(keyname, new ModelState()); ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null)); update_content.Media = address; update_content.Url = address; } } else { //ok, making the new filename string filepath = string.Format("projects/{0}/update_{1}/{2}", ProjectID, update_content.UpdateID, file.FileName); var request = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath); request.InputStream = file.InputStream; AmazonS3Client.PutObject(request); string address = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath; ModelState.Remove(keyname); ModelState.Add(keyname, new ModelState()); ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null)); update_content.Media = address; update_content.Url = address; } } catch (Exception ex) { ModelState.AddModelError(keyname, "Upload error: " + ex.Message); return(RedirectToAction("Edit", "Update", new { id = update_content.UpdateID })); } } } } if (update_content.Date == null) { update_content.Date = DateTime.Now; } update_content.DateCreated = DateTime.Now; update_content.UserID = CurrentUser.UserID; if (ModelState.IsValid) { db.update_content.Attach(update_content); db.ObjectStateManager.ChangeObjectState(update_content, EntityState.Modified); db.SaveChanges(); return(RedirectToAction("Edit", "Update", new { id = update_content.UpdateID })); } return(RedirectToAction("Edit", "Update", new { id = update_content.UpdateID })); }