public static void UpdateDocument(this Document document, DocumentUpdateViewModel documentUpdateViewModel) { document.Name = documentUpdateViewModel.Name; document.Summary = documentUpdateViewModel.Summary; document.Tag = documentUpdateViewModel.Tag; document.Content = documentUpdateViewModel.Content; }
private DocumentUpdateViewModel FillNullValues(DocumentUpdateViewModel model) { model.CourseName = db.Courses.Find(model.CourseId)?.Name; model.ModuleName = db.Courses.Find(model.ModuleId)?.Name; model.ActivityName = db.Courses.Find(model.ActivityId)?.Name; model.Types = DocumentTypeSelectList(); return(model); }
public ActionResult Edit([Bind(Include = "SelectedTypeId,Description,Deadline,CourseId,ModuleId,ActivityId,Document")] DocumentUpdateViewModel model) { if (!ModelState.IsValid) { model = FillNullValues(model); return(View(model)); } Document document = model.Document; document.TypeId = model.SelectedTypeId; document.Description = model.Description; document.Deadline = model.Deadline; db.SaveChanges(); return(RedirectToParent(document)); }
// GET: Documents/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Document document = db.Documents.Find(id); if (document == null) { return(HttpNotFound()); } DocumentUpdateViewModel model = PopulateFromDocument(document); return(View(model)); }
// GET: Documents/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(RedirectToAction("Index", "Courses")); } Document document = db.Documents.Find(id); if (document == null) { return(HttpNotFound()); } DocumentUpdateViewModel model = PopulateFromDocument(document); return(View(model)); }
public ActionResult Edit(Guid? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var document = GetDocumentById(id, db); DocumentUpdateViewModel documentUpdateViewModel = new DocumentUpdateViewModel { Id = document.Id, Name = document.Name, Summary = document.Summary, Tag = document.Tag, Content = document.Content, DocumentFiles = document.DocumentFiles }; return View(documentUpdateViewModel); }
public ActionResult Update(DocumentUpdateViewModel model, HttpPostedFileBase file) { if (ModelState.IsValid) { this.documents.Update( model.Id, model.Title, model.Description, model.Code, model.ProcedureId); if (file != null) { this.SaveDocumentFile(model.Id, file); } TempData["Success"] = SuccessMessagesConstants.DocumentUpdated; return(RedirectToAction("Details", new { id = model.Id })); } return(View(model)); }
public ActionResult Edit(DocumentUpdateViewModel documentUpdateViewModel) { Document document = db.Documents.Find(documentUpdateViewModel.Id); document.UpdateDocument(documentUpdateViewModel); document.Update(User.Identity.Name); if (ModelState.IsValid) { List<DocumentFile> fileDetails = new List<DocumentFile>(); for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); DocumentFile fileDetail = new DocumentFile() { Name = fileName, Type = Path.GetExtension(fileName), Id = Guid.NewGuid() }; fileDetails.Add(fileDetail); long? size = file.ContentLength; fileDetail.Size = size.ToString(); fileDetail.Path = Path.GetExtension(fileName); var path = Path.Combine(Server.MapPath(_uploadPath), fileDetail.Id + fileDetail.Path); document.DocumentFiles = fileDetails; file.SaveAs(path); db.Entry(fileDetail).State = EntityState.Added; } } db.Entry(document).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(document); }
public ActionResult Update(DocumentUpdateViewModel model, HttpPostedFileBase file) { if (ModelState.IsValid) { this.documents.Update( model.Id, model.Title, model.Description, model.Code, model.ProcedureId); if (file != null) { this.SaveDocumentFile(model.Id, file); } TempData["Success"] = SuccessMessagesConstants.DocumentUpdated; return RedirectToAction("Details", new { id = model.Id }); } return View(model); }