public PostRateConfirmationDto Update(Guid id, PostRateCreateDto dto) { Post post = PostMock.Posts.FirstOrDefault(e => e.Id == dto.PostId); if (post == null) { return(null); } var rate = _context.PostRate.FirstOrDefault(e => e.Id == id); if (rate == null) { return(null); } rate.Description = dto.Description; rate.RateScale = dto.RateScale; rate.RateTypeId = dto.RateTypeId; rate.PostId = dto.PostId; _context.SaveChanges(); _logger.Log("Update PostRate"); return(_mapper.Map <PostRateConfirmationDto>(rate)); }
public PostRateConfirmationDto Create(PostRateCreateDto dto) { Post post = PostMock.Posts.FirstOrDefault(e => e.Id == dto.PostId); if (post == null) { return(null); } PostRate newRate = new PostRate() { Id = Guid.NewGuid(), Description = dto.Description, RateScale = dto.RateScale, RateTypeId = dto.RateTypeId, PostId = dto.PostId }; _context.PostRate.Add(newRate); _context.SaveChanges(); _logger.Log("Create PostRate"); return(_mapper.Map <PostRateConfirmationDto>(newRate)); }
public ActionResult Put(Guid id, PostRateCreateDto dto) { var entity = _service.Update(id, dto); if (entity == null) { return(NotFound()); } return(Ok(entity)); }
public ActionResult Post([FromBody] PostRateCreateDto dto) { var entity = _service.Create(dto); return(Ok(entity)); }