public async Task<CommentDTO> AddAsync(CommentDTO dtoModel) { await this.ValidateAsync(dtoModel); Comment comment = new Comment(); dtoModel.DateCreated = DateTime.Now; dtoModel.LastDateModified = DateTime.Now; CommentMapper.MapCommentFromCommentDto(ref comment, ref dtoModel); this.repository.Add(comment); await this.repository.SaveChangesAsync(); dtoModel.Id = comment.Id; return dtoModel; }
public async Task<CommentDTO> UpdateAsync(CommentDTO dtoModel) { await this.ValidateAsync(dtoModel); var commentEntity = await this.repository.Get(dtoModel.Id).FirstOrDefaultAsync(); if (commentEntity == null) { throw new Exception("Comment for update not found"); } dtoModel.LastDateModified = DateTime.Now; CommentMapper.MapCommentFromCommentDto(ref commentEntity, ref dtoModel); this.repository.Update(commentEntity); await this.repository.SaveChangesAsync(); return dtoModel; }