public ActionResult DeleteConfirmed(int id) { MemberMedia MemberMedia = db.MemberMedia.Find(id); db.MemberMedia.Remove(MemberMedia); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteMyProfPic(int id) { MemberMedia mm = db.MemberMedias.Find(id); db.MemberMedias.Remove(mm); db.SaveChanges(); return(RedirectToAction("Edit", "Members")); }
public ActionResult Edit([Bind(Include = "mediaID,ID,mediaTypeID,path")] MemberMedia MemberMedia) { if (ModelState.IsValid) { db.Entry(MemberMedia).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.mediaTypeID = new SelectList(db.MediaType, "mediaTypeID", "name", MemberMedia.mediaTypeID); ViewBag.ID = new SelectList(db.Member, "ID", "FirstName1", MemberMedia.ID); return(View(MemberMedia)); }
// GET: MemberMedias/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MemberMedia MemberMedia = db.MemberMedia.Find(id); if (MemberMedia == null) { return(HttpNotFound()); } return(View(MemberMedia)); }
// GET: MemberMedias/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MemberMedia MemberMedia = db.MemberMedia.Find(id); if (MemberMedia == null) { return(HttpNotFound()); } ViewBag.mediaTypeID = new SelectList(db.MediaType, "mediaTypeID", "name", MemberMedia.mediaTypeID); ViewBag.ID = new SelectList(db.Member, "ID", "FirstName1", MemberMedia.ID); return(View(MemberMedia)); }
private string ProcessPicture(Member tblMember, HttpPostedFileBase file) { string resultMessage = ""; if (file != null) { string _path = ""; string _serverPath = Server.MapPath("~/Content/Images/members/profilepics"); string _fileName = Path.GetFileName(file.FileName); string _fileExt = _fileName.Substring(_fileName.Length - 4); //from http://www.codeproject.com/Tips/481015/Rename-Resize-Upload-Image-ASP-NET-MVC ImageUpload imageUpload = new ImageUpload { Width = 600 }; //set Width here ImageResult imageResult = imageUpload.RenameUploadFile(file); if (imageResult.Success) { //TODO: write the filename to the db //save path for image to membermedia in db MemberMedia mm = new MemberMedia(); mm.MemberID = tblMember.MemberID; _path = "/Content/Images/members/profilepics/" + imageResult.ImageName; mm.Path = _path; int countExistingMM = db.MemberMedias.Where(m => m.MemberID == tblMember.MemberID).Count(); if (countExistingMM == 0) { mm.PrimaryPic = true; } tblMember.MemberMedias.Add(mm); resultMessage = "Successfully Uploaded Image"; } else { // use imageResult.ErrorMessage to show the error resultMessage = "Successfully Uploaded Image"; } db.SaveChanges(); } return(resultMessage); }
public ActionResult AssignPrimary(int id) { MemberMedia mm = db.MemberMedias.Find(id); mm.PrimaryPic = true; long memberID = (long)mm.MemberID; List <MemberMedia> mms = db.MemberMedias.Where(m => m.MemberID == memberID && m.MemberMediaID != id).ToList <MemberMedia>(); foreach (MemberMedia i in mms) { i.PrimaryPic = false; } db.SaveChanges(); return(RedirectToAction("Edit", "Members")); }
private string ProcessAndUploadPicture(Member Member, HttpPostedFileBase file) { if (file != null) { string _fileName = Path.GetFileName(file.FileName); string _fileExt = _fileName.Substring(_fileName.Length - 4); //Process Picture //from http://www.codeproject.com/Tips/481015/Rename-Resize-Upload-Image-ASP-NET-MVC ImageUpload imageUpload = new ImageUpload { Width = 600 }; //set Width here //Upload Picture ImageResult imageResult = imageUpload.RenameUploadFile(file); if (imageResult.Success) { //TODO: write the filename to the db //save path for image to membermedia in db MemberMedia mm = new MemberMedia(); mm.ID = (int)Member.ID; string uploadPath = config.PhotoUploadPath; mm.path = uploadPath + imageResult.ImageName; Member.MemberMedia.Add(mm); db.SaveChanges(); return("Successfully Uploaded Image"); } else { // use imageResult.ErrorMessage to show the error return("Failed to Upload Image"); } } else { return("File is empty"); } }