public async Task <ActionResult <ControllerResponse <GetProjectTaskDto> > > update(string id, UpdateProjectTaskDto projectTaskIn) { string userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier).ToString(); var projectTask = await _projectTaskService.getByIdAsync(id); if (projectTask.userId != userId) { throw new UnauthorizedAccessException("ProjectTask don't belong to you"); } projectTask = _mapper.Map <UpdateProjectTaskDto, ProjectTask>(projectTaskIn, projectTask); await _projectTaskService.updateAsync(id, projectTask); return(Ok(new ControllerResponse <GetProjectTaskDto> { data = _mapper.Map <GetProjectTaskDto>(projectTask) })); }
public async Task <ActionResult <ControllerResponse <ProjectLog> > > create(CreateProjectLogDto createProjectLog) { string userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier).ToString(); ProjectLog projectLog = _mapper.Map <ProjectLog>(createProjectLog); projectLog.userId = userId; projectLog.project = await _projectService.getByIdAsync(createProjectLog.projectId); if (projectLog.project == null) { throw new ArgumentException("There is no project with corresponding id"); } if (projectLog.project.userId != userId) { throw new UnauthorizedAccessException("Project don't belong to you"); } if (createProjectLog.projectTaskId != null) { projectLog.projectTask = await _projectTaskService.getByIdAsync(createProjectLog.projectTaskId); if (projectLog.projectTask.userId != userId) { throw new UnauthorizedAccessException("ProjectTask don't belong to you"); } } if (createProjectLog.type != PROJECT_TYPE.BREAK) { createProjectLog.type = projectLog.project.projectType; } projectLog = await _projectLogService.processCreateProjectLog(projectLog); return(Created(new Uri($"{Request.Path}/{projectLog.id}", UriKind.Relative), new ControllerResponse <ProjectLog> { data = projectLog })); }