public async Task <ActionResult <SolutionDTO> > PostSolution(CreateSolutionDTO solution) { Solution newSolution = new Solution(solution.Description, new Guid(User.Identity.Name), solution.Mark, solution.LaboratoryWorkId); try { await _context.Solutions.AddAsync(newSolution); await _context.SaveChangesAsync(); return(Ok(newSolution.ToSolutionDto())); } catch (Exception ex) { _logger.LogError(ex.Message); return(StatusCode(500)); } }
public async Task <ActionResult <SolutionDTO> > GetMySolution(Guid id) { var solution = await _context.Solutions.Include(c => c.LaboratoryWork).Include(c => c.Files) .Where(c => c.LaboratoryWorkId == id && c.OwnerId == new Guid(User.Identity.Name)).FirstOrDefaultAsync(); if (solution == null) { var newSolution = new CreateSolutionDTO { Id = Guid.NewGuid(), Description = "", LaboratoryWorkId = id, Mark = 0, }; await PostSolution(newSolution); await _context.SaveChangesAsync(); solution = await _context.Solutions.Include(c => c.LaboratoryWork).Include(c => c.Files) .Where(c => c.LaboratoryWorkId == id && c.OwnerId == new Guid(User.Identity.Name)).FirstOrDefaultAsync(); } return(Ok(solution.ToSolutionDto())); }