public async Task <ProjectDto> AddProject(SaveProjectDto projectDto) { TinyMapper.Bind <SaveProjectDto, Project>(); TinyMapper.Bind <Project, ProjectDto>(); var project = TinyMapper.Map <Project>(projectDto); project.Created = UnixTimeStamp(); await _projectRepository.AddAsync(project); await _projectRepository.CommitAsync(); return(TinyMapper.Map <ProjectDto>(project)); }
public async Task <IActionResult> UpdateProject([FromBody] SaveProjectDto projectDto) { var userEmail = HttpContext.User.GetEmail(); if (string.IsNullOrEmpty(userEmail)) { return(BadRequest("User e-mail is missing.")); } projectDto.Email = userEmail; await _projectService.UpdateProject(projectDto); return(Ok()); }
public async Task UpdateProject(SaveProjectDto projectDto) { TinyMapper.Bind <List <SheetEntryDto>, List <SheetEntry> >(); var project = await _projectRepository.GetByIdAsync(projectDto.ProjectId); if (project == null) { throw new ArgumentException("Project not found"); } if (project.Email != projectDto.Email) { throw new ArgumentException("Project e-mail is not matched with user e-mail"); } project.Entries = TinyMapper.Map <List <SheetEntry> >(projectDto.Entries); project.Name = projectDto.Name; _projectRepository.NotifyChange(project); await _projectRepository.CommitAsync(); }