public EditDocumentModel(long nDocID) : this() { Document doc = new Document(); string result = OBSDataSource.GetDocument(nDocID, out doc); if (string.IsNullOrEmpty(result)) { Title = doc.Title; OriginalContent = doc.OriginalDocumentContent; SimplifiedContent = doc.SimplifiedContent; CarerID = doc.AuthorId; DocumentID = nDocID; IsFavourite = doc.IsFavourite; IsCompleted = doc.IsCompleted; Summary = doc.Summary; BasicJSONData = JsonConvert.SerializeObject(new { UserName = this.User.FullName(), DocumentTitle = doc.Title, DocumentId = doc.Id }); } else { Error = result; } }
public System.Web.Mvc.ActionResult SaveDocument(EditDocumentModel model) { string strErrorMessage = string.Empty; long nDocID = 0; Document doc = new Document(); doc.DateModified = DateTime.Now; doc.IsCompleted = model.IsCompleted; doc.OriginalDocumentContent = model.OriginalContent; doc.SimplifiedContent = model.SimplifiedContent; doc.Title = model.Title; doc.AuthorId = model.User.AccountId;//model.CarerID == 0 ? model.User.AccountId : model.CarerID; doc.UserId = model.User.AccountId; doc.Id = model.DocumentID; doc.IsFavourite = model.IsFavourite; doc.Summary = model.Summary; doc.Id = model.DocumentID; string result = OBSDataSource.SaveDocument(doc, out nDocID); if (string.IsNullOrEmpty(result)) { //model. += UserLogging.LogUserAction(UserOperations.SaveDocument, model.User, LoggingOperationLevel.Level1, new object[] { doc.Id }, false); //UserLogging.LogUserAction(model. UserLogging.LogUserAction(model.UserActionsLog); UserLogging.LogUserAction(UserOperations.SaveDocument, model.User, LoggingOperationLevel.Level1, new object[] { doc.Id }); return RedirectToAction("List", "Documents"); } else { ViewBag.IsUnSaved = true; ModelState.AddModelError("Model", result); return View("EditDocument", model); } }
public System.Web.Mvc.ActionResult NewDocument(EditDocumentModel model) { string strErrorMessage = string.Empty; if (ModelState.IsValid) { ModelState.Clear(); model.IsNewDocument = false; OriginalUserDocument newDocument = new OriginalUserDocument(); Document simpDocument = new Document(); if (model.User.Role == AccountRoles.User) { simpDocument.AuthorId = model.User.AccountId; simpDocument.UserId = model.User.AccountId; } else if (model.User.Role == AccountRoles.Carer) { simpDocument.AuthorId = model.User.AccountId; simpDocument.UserId = model.ReceiverID; } if (!string.IsNullOrEmpty(model.Content)) { newDocument.Text = model.Content; newDocument.Type = OriginalDocumentType.odtString; } else if (!string.IsNullOrEmpty(model.URL)) { newDocument.Url = model.URL; newDocument.Type = OriginalDocumentType.odtUrl; } else if (model.FileForConvert.HasTextMIME() && model.FileForConvert.HasTextFile()) { newDocument.FileName = model.FileForConvert.FileName; newDocument.FileContent = model.FileForConvert.GetContent(); newDocument.Type = OriginalDocumentType.odtFile; } string result = String.Empty; if (String.IsNullOrEmpty(model.Content) && String.IsNullOrEmpty(model.URL) && (!model.FileForConvert.HasTextMIME() || !model.FileForConvert.HasTextFile())) { result = ClientDefault.EditDocument_NoTextInput; } else { if (model.User.Role == AccountRoles.User) { result = OBSDataSource.SimplifyDocument(model.User.AccountId, newDocument, out simpDocument); } else if (model.User.Role == AccountRoles.Carer) { result = OBSDataSource.SimplifyCarerDocument(model.ReceiverID, newDocument, out simpDocument); } } if (string.IsNullOrEmpty(result)) { model.OriginalContent = simpDocument.OriginalDocumentContent; model.SimplifiedContent = simpDocument.SimplifiedContent; model.DocumentID = simpDocument.Id; model.Summary = simpDocument.Summary; AccountInfo currentUser = CurrentUser.Details(User.Identity.Name); model.UserActionsLog = UserLogging.LogUserAction(UserOperations.OpenDocument, currentUser, LoggingOperationLevel.Level1, new object[] { model.DocumentID }, false); if (model.User.Role == AccountRoles.Carer) { DocumentReviewModel reviewModel = new DocumentReviewModel(simpDocument); return View("DocumentReview", reviewModel); } } else { ModelState.AddModelError("Model", result); model.IsNewDocument = true; View("EditDocument", model); } } ViewBag.IsUnSaved = "true"; return View("EditDocument", model); }
public System.Web.Mvc.ActionResult DocumentReview(DocumentReviewModel model) { bool HasError = false; string result = string.Empty; Document doc = new Document(); long docId = model.DocumentId; // new document if (docId == 0) { doc.SimplifiedContent = model.SimplifiedContent; doc.OriginalDocumentContent = model.OriginalContent; doc.UserId = model.UserId; doc.AuthorId = model.CarerId; doc.IsPrivate = false; doc.IsRead = false; doc.IsFavourite = false; doc.Title = model.DocumentTitle; doc.IsCompleted = false; doc.DateModified = DateTime.Now; result = OBSDataSource.SaveCarerEditedDocument(doc, out docId); if (!string.IsNullOrEmpty(result)) { model.ErrorMessage = result; HasError = true; } else { AccountInfo user = new AccountInfo(); OBSDataSource.GetUserProfile(model.CarerId, out user); UserLogging.LogUserAction(model.UserActionsLog); UserLogging.LogUserAction(UserOperations.SaveDocument, user, LoggingOperationLevel.Level1, new object[] { doc.Id }); } } else { result = OBSDataSource.GetDocument(model.DocumentId, out doc); if (string.IsNullOrEmpty(result)) { doc.SimplifiedContent = model.SimplifiedContent; doc.Title = model.DocumentTitle; doc.Summary = model.Summary; result = OBSDataSource.SaveCarerEditedDocument(doc, out docId); if (!string.IsNullOrEmpty(result)) { model.ErrorMessage = result; HasError = true; } else { AccountInfo user = new AccountInfo(); OBSDataSource.GetUserProfile(model.CarerId, out user); UserLogging.LogUserAction(model.UserActionsLog); UserLogging.LogUserAction(UserOperations.SaveDocument, user, LoggingOperationLevel.Level1, new object[] { doc.Id }); } } else { model.ErrorMessage = result; HasError = true; } } if (HasError) { return View("DocumentReview", model); } else { return RedirectToAction("UserList", "Documents", new { id = model.UserId }); //return RedirectToRoute(string.Format("/Documents/UserList/{0}", model.UserId)); } }