public async Task <IActionResult> GetProjectDetails(int projectId) { var projectDetails = (await _unitOfWork.ProjectDetailsRepository .ApplyAsync(new ProjectDetailsByProjectIdSpecification(projectId))) .FirstOrDefault(); if (projectDetails == null) { return(this.NotFound()); } return(this.Ok(ProjectDetailsOutputModel.FromEntity(projectDetails))); }
public async Task <IActionResult> CreateProjectDetail([FromBody] ProjectDetailInputModel inputModelModel, int projectId) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } var authority = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; var images = (await Task.WhenAll(inputModelModel.Images .Select(x => _uploadImageService.UploadImage(x.Value, authority)) .ToList())) .ToList(); var tags = inputModelModel.Tags .Select(x => new Tag() { Name = x.Name }) .ToList(); var links = inputModelModel.Links .Select(x => new Link() { Href = x.Href, Name = x.Name }) .ToList(); var projectDetails = new ProjectDetail() { ProjectId = projectId, Description = inputModelModel.Description, Info = inputModelModel.Info, }; projectDetails.ProjectDetailImages = images .Select(x => new ProjectDetailImage() { Image = x, ProjectDetail = projectDetails }) .ToList(); projectDetails.ProjectDetailTags = tags .Select(x => new ProjectDetailTag() { Tag = x, ProjectDetail = projectDetails }) .ToList(); projectDetails.ProjectDetailLinks = links .Select(x => new ProjectDetailLink() { Link = x, ProjectDetail = projectDetails }) .ToList(); _unitOfWork.ProjectDetailsRepository.Add(projectDetails); await _unitOfWork.CompleteAsync(); return(this.Ok(ProjectDetailsOutputModel.FromEntity(projectDetails))); }