//[Authorize(Roles = "Carer")]
        public System.Web.Mvc.ActionResult DocumentReview(long docId, long userId)
        {
            DocumentReviewModel model = new DocumentReviewModel(docId, userId);
            OBSDataSource.MarkDocumentAsRead(docId);

            AccountInfo user = new AccountInfo();
            OBSDataSource.GetUserProfile(model.CarerId, out user);

            model.UserActionsLog = UserLogging.LogUserAction(UserOperations.OpenDocument, user, LoggingOperationLevel.Level1, new object[] { model.DocumentId }, false);

            return View("DocumentReview", 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));
            }
        }