public async Task <ActionResult <WorkflowDirection_WorkflowDirectionDTO> > Create([FromBody] WorkflowDirection_WorkflowDirectionDTO WorkflowDirection_WorkflowDirectionDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } if (!await HasPermission(WorkflowDirection_WorkflowDirectionDTO.Id)) { return(Forbid()); } WorkflowDirection WorkflowDirection = ConvertDTOToEntity(WorkflowDirection_WorkflowDirectionDTO); WorkflowDirection = await WorkflowDirectionService.Create(WorkflowDirection); WorkflowDirection_WorkflowDirectionDTO = new WorkflowDirection_WorkflowDirectionDTO(WorkflowDirection); if (WorkflowDirection.IsValidated) { return(WorkflowDirection_WorkflowDirectionDTO); } else { return(BadRequest(WorkflowDirection_WorkflowDirectionDTO)); } }
public async Task <WorkflowDirection> Delete(WorkflowDirection WorkflowDirection) { if (!await WorkflowDirectionValidator.Delete(WorkflowDirection)) { return(WorkflowDirection); } try { await UOW.Begin(); await UOW.WorkflowDirectionRepository.Delete(WorkflowDirection); await UOW.Commit(); await Logging.CreateAuditLog(new { }, WorkflowDirection, nameof(WorkflowDirectionService)); return(WorkflowDirection); } catch (Exception ex) { await UOW.Rollback(); await Logging.CreateSystemLog(ex.InnerException, nameof(WorkflowDirectionService)); if (ex.InnerException == null) { throw new MessageException(ex); } else { throw new MessageException(ex.InnerException); } } }
public async Task <bool> Delete(WorkflowDirection WorkflowDirection) { if (await ValidateId(WorkflowDirection)) { await CanDelete(WorkflowDirection); } return(WorkflowDirection.IsValidated); }
public async Task <bool> Create(WorkflowDirection WorkflowDirection) { await ValidateWorkflowDirection(WorkflowDirection); await ValidateStep(WorkflowDirection); await ValidateSubjectMail(WorkflowDirection); return(WorkflowDirection.IsValidated); }
public async Task <bool> Update(WorkflowDirection WorkflowDirection) { if (await ValidateId(WorkflowDirection)) { await ValidateWorkflowDirection(WorkflowDirection); await ValidateStep(WorkflowDirection); await ValidateSubjectMail(WorkflowDirection); } return(WorkflowDirection.IsValidated); }
private async Task <bool> ValidateStep(WorkflowDirection WorkflowDirection) { if (WorkflowDirection.FromStepId == 0) { WorkflowDirection.AddError(nameof(WorkflowDirectionValidator), nameof(WorkflowDirection.FromStep), ErrorCode.FromStepEmpty); } else { WorkflowStepFilter WorkflowStepFilter = new WorkflowStepFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = WorkflowDirection.FromStepId }, WorkflowDefinitionId = new IdFilter { Equal = WorkflowDirection.WorkflowDefinitionId }, Selects = WorkflowStepSelect.Id }; int count = await UOW.WorkflowStepRepository.Count(WorkflowStepFilter); if (count == 0) { WorkflowDirection.AddError(nameof(WorkflowDirectionValidator), nameof(WorkflowDirection.FromStep), ErrorCode.FromStepNotExisted); } } if (WorkflowDirection.ToStepId == 0) { WorkflowDirection.AddError(nameof(WorkflowDirectionValidator), nameof(WorkflowDirection.ToStep), ErrorCode.ToStepEmpty); } else { WorkflowStepFilter WorkflowStepFilter = new WorkflowStepFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = WorkflowDirection.ToStepId }, WorkflowDefinitionId = new IdFilter { Equal = WorkflowDirection.WorkflowDefinitionId }, Selects = WorkflowStepSelect.Id }; int count = await UOW.WorkflowStepRepository.Count(WorkflowStepFilter); if (count == 0) { WorkflowDirection.AddError(nameof(WorkflowDirectionValidator), nameof(WorkflowDirection.ToStep), ErrorCode.ToStepNotExisted); } } return(WorkflowDirection.IsValidated); }
private async Task <bool> ValidateSubjectMail(WorkflowDirection WorkflowDirection) { if (!string.IsNullOrWhiteSpace(WorkflowDirection.SubjectMailForCreator) && WorkflowDirection.SubjectMailForCreator.Length > 255) { WorkflowDirection.AddError(nameof(WorkflowDirectionValidator), nameof(WorkflowDirection.SubjectMailForCreator), ErrorCode.SubjectMailForCreatorOverLength); } if (!string.IsNullOrWhiteSpace(WorkflowDirection.SubjectMailForNextStep) && WorkflowDirection.SubjectMailForNextStep.Length > 255) { WorkflowDirection.AddError(nameof(WorkflowDirectionValidator), nameof(WorkflowDirection.SubjectMailForNextStep), ErrorCode.SubjectMailForNextStepOverLength); } return(WorkflowDirection.IsValidated); }
public async Task <WorkflowDirection> Get(long Id) { WorkflowDirection WorkflowDirection = await DataContext.WorkflowDirection.AsNoTracking() .Where(x => x.Id == Id).Select(x => new WorkflowDirection() { Id = x.Id, WorkflowDefinitionId = x.WorkflowDefinitionId, FromStepId = x.FromStepId, ToStepId = x.ToStepId, SubjectMailForCreator = x.SubjectMailForCreator, SubjectMailForNextStep = x.SubjectMailForNextStep, BodyMailForCreator = x.BodyMailForCreator, BodyMailForNextStep = x.BodyMailForNextStep, FromStep = x.FromStep == null ? null : new WorkflowStep { Id = x.FromStep.Id, WorkflowDefinitionId = x.FromStep.WorkflowDefinitionId, Code = x.FromStep.Code, Name = x.FromStep.Name, RoleId = x.FromStep.RoleId, SubjectMailForReject = x.FromStep.SubjectMailForReject, BodyMailForReject = x.FromStep.BodyMailForReject, }, ToStep = x.ToStep == null ? null : new WorkflowStep { Id = x.ToStep.Id, WorkflowDefinitionId = x.ToStep.WorkflowDefinitionId, Code = x.ToStep.Code, Name = x.ToStep.Name, RoleId = x.ToStep.RoleId, SubjectMailForReject = x.ToStep.SubjectMailForReject, BodyMailForReject = x.ToStep.BodyMailForReject, }, WorkflowDefinition = x.WorkflowDefinition == null ? null : new WorkflowDefinition { Id = x.WorkflowDefinition.Id, Code = x.WorkflowDefinition.Code, Name = x.WorkflowDefinition.Name, WorkflowTypeId = x.WorkflowDefinition.WorkflowTypeId, StartDate = x.WorkflowDefinition.StartDate, EndDate = x.WorkflowDefinition.EndDate, StatusId = x.WorkflowDefinition.StatusId, UpdatedAt = x.WorkflowDefinition.UpdatedAt, }, }).FirstOrDefaultAsync(); if (WorkflowDirection == null) { return(null); } return(WorkflowDirection); }
public WorkflowDefinition_WorkflowDirectionDTO(WorkflowDirection WorkflowDirection) { this.Id = WorkflowDirection.Id; this.WorkflowDefinitionId = WorkflowDirection.WorkflowDefinitionId; this.FromStepId = WorkflowDirection.FromStepId; this.ToStepId = WorkflowDirection.ToStepId; this.SubjectMailForCreator = WorkflowDirection.SubjectMailForCreator; this.SubjectMailForNextStep = WorkflowDirection.SubjectMailForNextStep; this.BodyMailForCreator = WorkflowDirection.BodyMailForCreator; this.BodyMailForNextStep = WorkflowDirection.BodyMailForNextStep; this.UpdatedAt = WorkflowDirection.UpdatedAt; this.FromStep = WorkflowDirection.FromStep == null ? null : new WorkflowDefinition_WorkflowStepDTO(WorkflowDirection.FromStep); this.ToStep = WorkflowDirection.ToStep == null ? null : new WorkflowDefinition_WorkflowStepDTO(WorkflowDirection.ToStep); this.Errors = WorkflowDirection.Errors; }
public async Task <ActionResult <WorkflowDirection_WorkflowDirectionDTO> > Get([FromBody] WorkflowDirection_WorkflowDirectionDTO WorkflowDirection_WorkflowDirectionDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } if (!await HasPermission(WorkflowDirection_WorkflowDirectionDTO.Id)) { return(Forbid()); } WorkflowDirection WorkflowDirection = await WorkflowDirectionService.Get(WorkflowDirection_WorkflowDirectionDTO.Id); return(new WorkflowDirection_WorkflowDirectionDTO(WorkflowDirection)); }
private WorkflowDirection ConvertDTOToEntity(WorkflowDirection_WorkflowDirectionDTO WorkflowDirection_WorkflowDirectionDTO) { WorkflowDirection WorkflowDirection = new WorkflowDirection(); WorkflowDirection.Id = WorkflowDirection_WorkflowDirectionDTO.Id; WorkflowDirection.WorkflowDefinitionId = WorkflowDirection_WorkflowDirectionDTO.WorkflowDefinitionId; WorkflowDirection.FromStepId = WorkflowDirection_WorkflowDirectionDTO.FromStepId; WorkflowDirection.ToStepId = WorkflowDirection_WorkflowDirectionDTO.ToStepId; WorkflowDirection.SubjectMailForCreator = WorkflowDirection_WorkflowDirectionDTO.SubjectMailForCreator; WorkflowDirection.SubjectMailForNextStep = WorkflowDirection_WorkflowDirectionDTO.SubjectMailForNextStep; WorkflowDirection.BodyMailForCreator = WorkflowDirection_WorkflowDirectionDTO.BodyMailForCreator; WorkflowDirection.BodyMailForNextStep = WorkflowDirection_WorkflowDirectionDTO.BodyMailForNextStep; WorkflowDirection.UpdatedAt = WorkflowDirection_WorkflowDirectionDTO.UpdatedAt; WorkflowDirection.FromStep = WorkflowDirection_WorkflowDirectionDTO.FromStep == null ? null : new WorkflowStep { Id = WorkflowDirection_WorkflowDirectionDTO.FromStep.Id, WorkflowDefinitionId = WorkflowDirection_WorkflowDirectionDTO.FromStep.WorkflowDefinitionId, Name = WorkflowDirection_WorkflowDirectionDTO.FromStep.Name, Code = WorkflowDirection_WorkflowDirectionDTO.FromStep.Code, RoleId = WorkflowDirection_WorkflowDirectionDTO.FromStep.RoleId, SubjectMailForReject = WorkflowDirection_WorkflowDirectionDTO.FromStep.SubjectMailForReject, BodyMailForReject = WorkflowDirection_WorkflowDirectionDTO.FromStep.BodyMailForReject, }; WorkflowDirection.ToStep = WorkflowDirection_WorkflowDirectionDTO.ToStep == null ? null : new WorkflowStep { Id = WorkflowDirection_WorkflowDirectionDTO.ToStep.Id, WorkflowDefinitionId = WorkflowDirection_WorkflowDirectionDTO.ToStep.WorkflowDefinitionId, Code = WorkflowDirection_WorkflowDirectionDTO.ToStep.Code, Name = WorkflowDirection_WorkflowDirectionDTO.ToStep.Name, RoleId = WorkflowDirection_WorkflowDirectionDTO.ToStep.RoleId, SubjectMailForReject = WorkflowDirection_WorkflowDirectionDTO.ToStep.SubjectMailForReject, BodyMailForReject = WorkflowDirection_WorkflowDirectionDTO.ToStep.BodyMailForReject, }; WorkflowDirection.WorkflowDefinition = WorkflowDirection_WorkflowDirectionDTO.WorkflowDefinition == null ? null : new WorkflowDefinition { Id = WorkflowDirection_WorkflowDirectionDTO.WorkflowDefinition.Id, Code = WorkflowDirection_WorkflowDirectionDTO.WorkflowDefinition.Code, Name = WorkflowDirection_WorkflowDirectionDTO.WorkflowDefinition.Name, WorkflowTypeId = WorkflowDirection_WorkflowDirectionDTO.WorkflowDefinition.WorkflowTypeId, StartDate = WorkflowDirection_WorkflowDirectionDTO.WorkflowDefinition.StartDate, EndDate = WorkflowDirection_WorkflowDirectionDTO.WorkflowDefinition.EndDate, StatusId = WorkflowDirection_WorkflowDirectionDTO.WorkflowDefinition.StatusId, UpdatedAt = WorkflowDirection_WorkflowDirectionDTO.WorkflowDefinition.UpdatedAt, }; WorkflowDirection.BaseLanguage = CurrentContext.Language; return(WorkflowDirection); }
private async Task <bool> CanDelete(WorkflowDirection WorkflowDirection) { RequestWorkflowDefinitionMappingFilter RequestWorkflowDefinitionMappingFilter = new RequestWorkflowDefinitionMappingFilter { Skip = 0, Take = 1, WorkflowDefinitionId = new IdFilter { Equal = WorkflowDirection.WorkflowDefinitionId } }; var count = await UOW.RequestWorkflowDefinitionMappingRepository.Count(RequestWorkflowDefinitionMappingFilter); if (count != 0) { WorkflowDirection.AddError(nameof(WorkflowDirectionValidator), nameof(WorkflowDirection.Id), ErrorCode.WorkflowDefinitionInUsed); } return(WorkflowDirection.IsValidated); }
public async Task <bool> ValidateId(WorkflowDirection WorkflowDirection) { WorkflowDirectionFilter WorkflowDirectionFilter = new WorkflowDirectionFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = WorkflowDirection.Id }, Selects = WorkflowDirectionSelect.Id }; int count = await UOW.WorkflowDirectionRepository.Count(WorkflowDirectionFilter); if (count == 0) { WorkflowDirection.AddError(nameof(WorkflowDirectionValidator), nameof(WorkflowDirection.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <WorkflowDirection> Get(long Id) { WorkflowDirection WorkflowDirection = await UOW.WorkflowDirectionRepository.Get(Id); if (WorkflowDirection == null) { return(null); } List <WorkflowParameter> WorkflowParameters = await UOW.WorkflowParameterRepository.List(new WorkflowParameterFilter { WorkflowDefinitionId = new IdFilter { Equal = WorkflowDirection.WorkflowDefinitionId }, Skip = 0, Take = int.MaxValue, Selects = WorkflowParameterSelect.ALL, }); WorkflowDirection.WorkflowParameters = WorkflowParameters; return(WorkflowDirection); }
public async Task <bool> Create(WorkflowDirection WorkflowDirection) { WorkflowDirectionDAO WorkflowDirectionDAO = new WorkflowDirectionDAO(); WorkflowDirectionDAO.Id = WorkflowDirection.Id; WorkflowDirectionDAO.WorkflowDefinitionId = WorkflowDirection.WorkflowDefinitionId; WorkflowDirectionDAO.FromStepId = WorkflowDirection.FromStepId; WorkflowDirectionDAO.ToStepId = WorkflowDirection.ToStepId; WorkflowDirectionDAO.SubjectMailForCreator = WorkflowDirection.SubjectMailForCreator; WorkflowDirectionDAO.SubjectMailForNextStep = WorkflowDirection.SubjectMailForNextStep; WorkflowDirectionDAO.BodyMailForCreator = WorkflowDirection.BodyMailForCreator; WorkflowDirectionDAO.BodyMailForNextStep = WorkflowDirection.BodyMailForNextStep; WorkflowDirectionDAO.CreatedAt = StaticParams.DateTimeNow; WorkflowDirectionDAO.UpdatedAt = StaticParams.DateTimeNow; DataContext.WorkflowDirection.Add(WorkflowDirectionDAO); await DataContext.SaveChangesAsync(); WorkflowDirection.Id = WorkflowDirectionDAO.Id; await SaveReference(WorkflowDirection); return(true); }
public async Task <bool> Update(WorkflowDirection WorkflowDirection) { WorkflowDirectionDAO WorkflowDirectionDAO = DataContext.WorkflowDirection.Where(x => x.Id == WorkflowDirection.Id).FirstOrDefault(); if (WorkflowDirectionDAO == null) { return(false); } WorkflowDirectionDAO.Id = WorkflowDirection.Id; WorkflowDirectionDAO.WorkflowDefinitionId = WorkflowDirection.WorkflowDefinitionId; WorkflowDirectionDAO.FromStepId = WorkflowDirection.FromStepId; WorkflowDirectionDAO.ToStepId = WorkflowDirection.ToStepId; WorkflowDirectionDAO.SubjectMailForCreator = WorkflowDirection.SubjectMailForCreator; WorkflowDirectionDAO.SubjectMailForNextStep = WorkflowDirection.SubjectMailForNextStep; WorkflowDirectionDAO.BodyMailForCreator = WorkflowDirection.BodyMailForCreator; WorkflowDirectionDAO.BodyMailForNextStep = WorkflowDirection.BodyMailForNextStep; WorkflowDirectionDAO.UpdatedAt = StaticParams.DateTimeNow; await DataContext.SaveChangesAsync(); await SaveReference(WorkflowDirection); return(true); }
private async Task <bool> ValidateWorkflowDirection(WorkflowDirection WorkflowDirection) { if (WorkflowDirection.WorkflowDefinitionId == 0) { WorkflowDirection.AddError(nameof(WorkflowDirectionValidator), nameof(WorkflowDirection.WorkflowDefinition), ErrorCode.WorkflowDefinitionEmpty); } else { WorkflowDefinitionFilter WorkflowDefinitionFilter = new WorkflowDefinitionFilter { Id = new IdFilter { Equal = WorkflowDirection.WorkflowDefinitionId } }; int count = await UOW.WorkflowDefinitionRepository.Count(WorkflowDefinitionFilter); if (count == 0) { WorkflowDirection.AddError(nameof(WorkflowDirectionValidator), nameof(WorkflowDirection.WorkflowDefinition), ErrorCode.WorkflowDefinitionNotExisted); } } return(WorkflowDirection.IsValidated); }
private async Task SaveReference(WorkflowDirection WorkflowDirection) { }
public async Task <bool> Delete(WorkflowDirection WorkflowDirection) { await DataContext.WorkflowDirection.Where(x => x.Id == WorkflowDirection.Id).DeleteFromQueryAsync(); return(true); }
public SharedToExtensionWorkflow(ISolution solution, WorkflowDirection direction, string actionId) : base(solution, actionId) { Direction = direction; }