public WorkTaskEditVM InitTask(int sourceType, long sourceId) { var model = new WorkTaskEditVM() { SourceType = sourceType, SourceId = sourceId, TaskExecutionId = WorkTaskConstants.TaskExecution.ByUser }; switch (sourceType) { case SourceTypeSelectVM.Document: var documentCaseInfo = repo.AllReadonly <Document>() .Include(x => x.DocumentCaseInfo) .Where(x => x.Id == sourceId) .Where(x => x.DocumentCaseInfo.Any()) .Select(x => x.DocumentCaseInfo.FirstOrDefault()) .FirstOrDefault(); //Ако в документа има свързано дело от същия съд, задачата се насочва по подразбиране на съдия-докладчика на делото if (documentCaseInfo != null && documentCaseInfo.CourtId == userContext.CourtId && documentCaseInfo.CaseId > 0) { var judgeReporterUserId = repo.AllReadonly <CaseLawUnit>() .Where(x => x.CaseId == documentCaseInfo.CaseId && x.CaseSessionId == null) .Where(x => (x.DateTo ?? DateTime.MaxValue) >= DateTime.Now) .Where(x => x.JudgeRoleId == NomenclatureConstants.JudgeRole.JudgeReporter) .Select(x => x.LawUnitUserId) .FirstOrDefault(); model.UserId = judgeReporterUserId; } break; } return(model); }
public bool RedirectTask(WorkTaskEditVM model) { try { var currentTask = repo.GetById <WorkTask>(model.Id); model.DescriptionCreated = currentTask.DescriptionCreated; if (!string.IsNullOrEmpty(currentTask.DescriptionCreated) && !string.IsNullOrEmpty(model.DescriptionRedirect)) { model.DescriptionCreated += ";" + model.DescriptionRedirect; } if (CreateTask(model)) { currentTask.TaskStateId = WorkTaskConstants.States.Redirected; currentTask.DateCompleted = DateTime.Now; repo.Update(currentTask); repo.SaveChanges(); return(true); } } catch (Exception ex) { logger.LogError(ex.Message); } return(false); }
public bool CreateTask(WorkTaskEditVM model) { try { var entity = new WorkTask(); model.ToEntity(entity); entity.CourtId = userContext.CourtId; entity.DateCreated = DateTime.Now; entity.UserCreatedId = userContext.UserId; entity.TaskStateId = WorkTaskConstants.States.New; var taskType = repo.GetById <TaskType>(model.TaskTypeId); if (taskType.SelfTask == true || entity.UserId == userContext.UserId) { entity.UserId = userContext.UserId; entity.DateAccepted = DateTime.Now; entity.TaskStateId = WorkTaskConstants.States.Accepted; } CreateTaskSourceDescription(entity); repo.Add(entity); repo.SaveChanges(); model.Id = entity.Id; return(true); } catch (Exception ex) { logger.LogError(ex.Message); return(false); } }
public JsonResult RedirectTask(WorkTaskEditVM model) { string validationError = ValidateTaskModel(model); if (!string.IsNullOrEmpty(validationError)) { return(Json(new { result = false, message = validationError })); } return(Json(new { result = workTaskService.RedirectTask(model) })); }
public JsonResult UpdateTask(WorkTaskEditVM model) { string validationError = ValidateTaskModel(model); if (!string.IsNullOrEmpty(validationError)) { return(Json(new { result = false, message = validationError })); } return(Json(new { result = workTaskService.UpdateTask(model), message = "Задачата е редактирана успешно." })); }
public bool UpdateTask(WorkTaskEditVM model) { try { var entity = repo.GetById <WorkTask>(model.Id); model.ToEntity(entity); repo.Update(entity); repo.SaveChanges(); return(true); } catch (Exception ex) { logger.LogError(ex.Message); return(false); } }
public async Task <IActionResult> DoTask_SentForSign(long id) { var task = taskService.Select_ById(id); switch (task.SourceType) { case SourceTypeSelectVM.DocumentResolution: var actId = task.SourceId; var actModel = drService.Select(0, actId).FirstOrDefault(); string actHTML = await GetActHTML(actModel); if (string.IsNullOrEmpty(actHTML)) { SetErrorMessage("Няма изготвен акт."); return(RedirectToAction("Edit", new { id = actId })); } await PrepareActFile(actModel, actHTML); var newTask = new WorkTaskEditVM() { ParentTaskId = id, SourceType = SourceTypeSelectVM.DocumentResolution, SourceId = actId, TaskTypeId = WorkTaskConstants.Types.DocumentResolution_Sign, TaskExecutionId = WorkTaskConstants.TaskExecution.ByUser, UserId = actModel.JudgeUserId, }; if (taskService.CreateTask(newTask)) { SetSuccessMessage("Задачата за подпис е създадена успешно."); taskService.CompleteTask(id); } else { SetErrorMessage("Проблем при създаване на задача"); } return(RedirectToAction("Edit", new { id = actId })); default: return(null); } }
private string ValidateTaskModel(WorkTaskEditVM model) { model.UserId = model.UserId.EmptyToNull("0"); string errorMessage = string.Empty; var taskType = commonService.GetById <TaskType>(model.TaskTypeId); if (model.TaskExecutionId == WorkTaskConstants.TaskExecution.ByUser && string.IsNullOrEmpty(model.UserId) && (taskType.SelfTask == false)) { errorMessage = "Изберете потребител."; } if (model.TaskExecutionId == WorkTaskConstants.TaskExecution.ByOrganization && model.CourtOrganizationId <= 0 && (taskType.SelfTask == false)) { errorMessage = "Изберете структура."; } if (model.Id == 0 && model.DateEnd.HasValue && model.DateEnd.Value.Date < DateTime.Now.Date) { errorMessage = "Срокът за изпълнение не може да бъде по-малък от днешна дата."; } if (!workTaskService.ValidateSourceCourt(model.SourceType, model.SourceId)) { errorMessage = $"Съда е променен на {userContext.CourtName}. Презаредете текущия екран."; } return(errorMessage); }
/// <summary> /// Запис на файл за документ /// </summary> /// <param name="id"></param> /// <param name="documentId"></param> /// <returns></returns> public async Task <IActionResult> GenerateDocumentFile(int id, long documentId) { if (!service.DocumentTemplate_UpdateDocumentId(id, documentId)) { SetErrorMessage("Проблем при изчитане на създаден документ"); return(RedirectToAction("Edit", "Document", new { id = documentId })); } var docTemplate = service.GetById <DocumentTemplate>(id); var headerModel = service.DocumentTemplate_InitHeader(id); byte[] fileBytes = null; if (docTemplate.HtmlTemplateId > 0) { string preparedBlank = await cdnService.LoadHtmlFileTemplate(new CdnFileSelect() { SourceType = SourceTypeSelectVM.DocumentTemplate, SourceId = id.ToString() }); fileBytes = await PdfBytesFromTemplate(docTemplate.Id, preparedBlank); //string html = FillBlankByTemplate(docTemplate.Id, preparedBlank); ////string html = await this.RenderPartialViewAsync("~/Views/Shared/", "PreviewRaw.cshtml", htmlModel, true); //fileBytes = await new ViewAsPdfByteWriter("CreatePdf", new BlankEditVM() { HtmlContent = html }).GetByte(this.ControllerContext); } else { int sourceType = SourceTypeSelectVM.DocumentTemplate; fileBytes = await GetFileBytes(headerModel, sourceType, id.ToString()); } var pdfRequest = new CdnUploadRequest() { SourceType = SourceTypeSelectVM.DocumentPdf, SourceId = documentId.ToString(), FileName = "documentTemplate.pdf", ContentType = "application/pdf", Title = $"{headerModel.DocumentTypeLabel} {headerModel.DocumentNumber}/{headerModel.DocumentDate:dd.MM.yyyy}", FileContentBase64 = Convert.ToBase64String(fileBytes) }; await cdnService.MongoCdn_AppendUpdate(pdfRequest); var newTask = new WorkTaskEditVM() { SourceType = SourceTypeSelectVM.Document, SourceId = documentId, TaskTypeId = WorkTaskConstants.Types.Document_Sign, UserId = headerModel.AuthorId, TaskExecutionId = WorkTaskConstants.TaskExecution.ByUser }; taskService.CreateTask(newTask); if (docTemplate.SourceType == SourceTypeSelectVM.ExchangeDoc) { await SaveFileExchangeDoc((int)docTemplate.SourceId); } SetSuccessMessage("Регистрирането на създадения документ премина успешно."); return(RedirectToAction("Edit", "Document", new { id = documentId })); }