public ActionResult ChangeProfile(UpdateProfileViewModel model, HttpPostedFileBase avatar) { var user = db.Accounts.Where(m => m.Username == User.Identity.Name).FirstOrDefault(); if (ModelState.IsValid) { user.Name = model.Name; user.DOB = model.DOB; user.Tel = model.Tel; //change avatar in profile if (avatar != null) { var img = Path.GetFileName(avatar.FileName); var pathImg = Path.Combine(Server.MapPath("~/Files/Avatar/"), img); avatar.SaveAs(pathImg); user.Avatar = img; } db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(Redirect("Profile")); } user.Avatar = model.Avatar; user.Name = model.Name; return(View("ChangeProfile", model)); }
public ActionResult EditFileInContribution(UpdateFileViewModel model, HttpPostedFileBase FileDoc, HttpPostedFileBase FileImg) { var file = db.Files.Where(m => m.Contribution.Id == model.ContributionId).FirstOrDefault(); if (ModelState.IsValid) { file.Name = model.Name; file.Description = model.Description; if (FileDoc != null) { string doc = System.IO.Path.GetFileName(FileDoc.FileName); string docPath = System.IO.Path.Combine(Server.MapPath("~/Files/Doc/"), doc); FileDoc.SaveAs(docPath); model.FileDoc = FileDoc != null ? doc : model.FileDoc; file.FileType = model.FileDoc; } if (FileImg != null) { string img = System.IO.Path.GetFileName(FileImg.FileName); string imgPath = System.IO.Path.Combine(Server.MapPath("~/Files/Image/"), img); FileImg.SaveAs(imgPath); model.FileImg = FileImg != null ? img : model.FileImg; file.FileName = model.FileImg; } db.Entry(file).State = EntityState.Modified; db.SaveChanges(); return(Redirect("Contribution")); } return(View(model)); }
public ActionResult AccountEdit(AdminEditAccViewModel model) { ViewBag.Roles = RoleList(); var obj = db.Accounts.Where(m => m.Username == model.Username).FirstOrDefault(); if (ModelState.IsValid) { obj.RoleId = model.NewRole; obj.Password = model.NewPassword; db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); return(Redirect("Account")); } return(View(model)); }
public ActionResult ApproveContribution(CommentViewModel model) { var obj = db.Contributions.Where(m => m.Id == model.ContributionId).FirstOrDefault(); obj.Status = model.Status; db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); return(Redirect("ContributionSubmited")); }
public ActionResult MagazineCreateOrEdit(Magazine magazine, HttpPostedFileBase PDFfile, HttpPostedFileBase ImgFile) { ViewBag.list = AcaYearList(); if (ModelState.IsValid) { Magazine obj = new Magazine(); obj.Id = magazine.Id; obj.Name = magazine.Name; obj.OpenDate = magazine.OpenDate; obj.CloseDate = magazine.CloseDate; obj.AcademicYearID = magazine.AcademicYearID; obj.Description = magazine.Description; if (magazine.Id == 0) { obj.Status = true; db.Magazines.Add(obj); db.SaveChanges(); } else { //upload file if (PDFfile != null) { string pdf = Path.GetFileName(PDFfile.FileName); string pdfPath = Path.Combine(Server.MapPath("~/Files/Doc/"), pdf); PDFfile.SaveAs(pdfPath); obj.PDFfile = pdf; } if (ImgFile != null) { string img = Path.GetFileName(ImgFile.FileName); string imgPath = Path.Combine(Server.MapPath("~/Files/Image/"), img); ImgFile.SaveAs(imgPath); obj.ImgFile = img; } obj.Status = magazine.Status; db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); } return(Redirect("Magazine")); } if (magazine.Id == 0) { return(View("MagazineCreate", magazine)); } return(View("MagazineEdit", magazine)); }