public ActionResult MoveTask(MoveTaskViewModel movetask) { int currentUID = AccountHelper.GetCurrentUser(User.Identity.Name).UID; if (ModelState.IsValid) { Worktask newObject = repository.Worktasks.Where(x => x.WorktaskID == movetask.WorktaskID).FirstOrDefault(); newObject = repository.Detail(newObject.WorktaskID); newObject.loadMetaInfo(repository, accRepository); Worktask oldObject = newObject.clone(); if (newObject != null) { newObject.BoardID = movetask.BoardID; newObject.WorkflowInstance.CurrentStateID = movetask.StateID; List <DiffInfo> diffInfos = newObject.Compare(oldObject); var diff = CompareObjExtensions.GenerateDiff("Cập nhật", diffInfos, currentUID, oldObject.WorktaskID); if (repository.SaveWorktask(newObject)) { if (repository.SaveHistory(diff)) { TempData["message"] = string.Format("Chuyển bảng công việc cho {0} thành công!", oldObject.Identify); return(RedirectToAction("Detail", new { taskcode = oldObject.Identify })); } } } return(View(movetask)); } else { TempData["message"] = string.Format(GetModelErrorMessages(ModelState)); return(View(movetask)); } }
public ActionResult InsertTask(Worktask worktask) { int currentUID = AccountHelper.GetCurrentUser(User.Identity.Name).UID; ElasticIndexService eService = new ElasticIndexService(); Worktask oldObject = null; if (ModelState.IsValid) { var isNew = false; // Assign Current user AS Owner, Assignee, Reporter if (worktask.Owner == 0) { worktask.Owner = currentUID; } if (worktask.Assignee == 0) { worktask.Assignee = currentUID; } if (worktask.Reporter == null || worktask.Reporter == 0) { worktask.Reporter = currentUID; } if (worktask.TaskType == 0) { worktask.TaskType = int.Parse(CategoryService.GetInstance().GetCategoryList(Contain.CatType.Category).ElementAt(1).Value); } if (worktask.Priority == 0) { worktask.Priority = int.Parse(CategoryService.GetInstance().GetCategoryList(Contain.CatType.Priority).ElementAt(1).Value); } if (worktask.WorktaskID == 0) { isNew = true; worktask.BoardID = this.GetLastViewedBoardId(User.Identity.Name); worktask.TaskMetas = new List <WorkTaskMetas>(); worktask = WorktaskService.GetInstance().loadMetaInfoFromRequest(worktask, Request); worktask.loadMetaInfo(repository, accRepository); // create workflow instance Board board = this.boardRepository.Get(worktask.BoardID); Workflow wf = board.Workflow; State firstState = wf.States.Where(s => s.Type == (int)Contain.StateType.Init).FirstOrDefault(); WorkflowInstance wfi = new WorkflowInstance() { WorkflowID = wf.ID, CurrentStateID = (firstState != null ? firstState.ID : 0) }; worktask.WorkflowInstance = wfi; worktask.Status = firstState.ID; } else { worktask = WorktaskService.GetInstance().loadMetaInfoFromRequest(worktask, Request); worktask.loadMetaInfo(repository, accRepository); oldObject = repository.Worktasks.Where(x => x.WorktaskID == worktask.WorktaskID).FirstOrDefault(); oldObject = repository.Detail(oldObject.WorktaskID); oldObject.loadMetaInfo(repository, accRepository); } var diff = new List <TaskHistory>(); if (repository.SaveWorktask(worktask)) { //save history worktask when create new string action = "Cập nhật"; if (isNew) { // Save data path for the new task string dataPathRoot = HostingEnvironment.MapPath(WebConfigurationManager.AppSettings["DataDirectoryRoot"]); string taskDataPath = Path.Combine(dataPathRoot, worktask.WorktaskID.ToString()); worktask.DataPath = taskDataPath; Directory.CreateDirectory(taskDataPath); action = "Tạo mới"; } List <DiffInfo> diffInfos = worktask.Compare(oldObject); diff = CompareObjExtensions.GenerateDiff(action, diffInfos, currentUID, worktask.WorktaskID); repository.SaveHistory(diff); foreach (var item in worktask.Attachment) { var text = String.Empty; if (System.IO.File.Exists(item.StoredPath)) { text = new TextExtractor().Extract(item.StoredPath).Text; } item.Metadata = text.Replace("\r", string.Empty).Replace("\n", string.Empty); } if (repository.SaveAttachmentFile(worktask)) { //save history diff = CompareObjExtensions.DetailedCompare(null, worktask.Attachment, currentUID, worktask.WorktaskID, isNew); if (repository.SaveHistory(diff)) { // Save Index in Elastic eService.CreateSingleIndex(repository.Detail(worktask.WorktaskID)); TempData["message"] = string.Format("Thông tin công việc {0} lưu thành công!", worktask.Identify); return(Json(new { taskId = worktask.WorktaskID, attachment = worktask.Attachment.Select(x => new { AttachmentID = x.AttachmentID, Name = x.Name }), success = true, redirectUrl = Url.Action("Detail", new { taskcode = worktask.Identify }) }, JsonRequestBehavior.AllowGet)); } } // Save Index in Elastic eService.CreateSingleIndex(repository.Detail(worktask.WorktaskID)); TempData["message"] = string.Format("Thông tin công việc {0} lưu thành công!", worktask.Identify); return(Json(new { taskId = worktask.WorktaskID, success = true, redirectUrl = Url.Action("Detail", new { taskcode = worktask.Identify }) }, JsonRequestBehavior.AllowGet)); } TempData["message"] = string.Format("Lưu không thành công"); return(Json(new { taskId = 0, success = false, message = TempData["message"] }, JsonRequestBehavior.AllowGet)); } else { TempData["message"] = string.Format(GetModelErrorMessages(ModelState)); return(Json(new { taskId = 0, success = false, message = TempData["message"] }, JsonRequestBehavior.AllowGet)); } }