public async Task <UpdateProjectStatusResponse> Handle(UpdateProjectStatusRequest request, CancellationToken cancellationToken) { var result = new UpdateProjectStatusResponse(); var project = await _context.Projects .Where(x => x.ProjectID == request.ProjectID) .SingleOrDefaultAsync(cancellationToken); if (project == null) { throw new NotFoundException(nameof(Project), request.ProjectID); } project.ProjectStatus = request.NewProjectStatus; await _context.SaveChangesAsync(cancellationToken); var projectStatusLog = new ProjectStatusLog { ProjectID = project.ProjectID, ProjectStatus = project.ProjectStatus, Comment = request.Comment }; await _context.ProjectStatusLogs.AddAsync(projectStatusLog); await _context.SaveChangesAsync(cancellationToken); result.IsSuccessful = true; result.ProjectID = project.ProjectID; result.NewProjectStatus = request.NewProjectStatus; return(result); }
public async Task <CreateProjectsResponse> Handle(CreateProjectsRequest request, CancellationToken cancellationToken) { var result = new CreateProjectsResponse() { IsSuccessful = false }; #region Check if Member already have Project var member = await _context.Projects .Where(x => x.MemberUsername == request.MemberUsername) .FirstOrDefaultAsync(cancellationToken); if (member != null) { result.ProjectID = member.ProjectID; return(result); } #endregion #region Add New Project var project = new Project { BlockchainID = request.BlockchainID, MemberUsername = request.MemberUsername, Name = request.Name, Description = request.Description, WalletAddress = request.WalletAddress, ProjectStatus = ProjectStatus.Draft }; await _context.Projects.AddAsync(project); await _context.SaveChangesAsync(cancellationToken); #endregion var projectStatusLog = new ProjectStatusLog { ProjectID = project.ProjectID, ProjectStatus = ProjectStatus.Draft, Comment = "Project has been created" }; await _context.ProjectStatusLogs.AddAsync(projectStatusLog); await _context.SaveChangesAsync(cancellationToken); result.IsSuccessful = true; result.ProjectID = project.ProjectID; return(result); }