public async Task <CommentDto> UpdateAsync(string id, CreateEditCommentDto dto) { var comment = await _unitOfWork.CommentRepository.FindAll(x => x.Id.Equals(id)).FirstOrDefaultAsync(); if (comment != null) { throw new NotFoundException($"Not found commone with id {id}"); } var entity = dto.ToEntity(comment); _unitOfWork.CommentRepository.Update(entity); await _unitOfWork.CommitAsync(); return(entity.ToDto()); }
public async Task <CommentDto> CreateAsync(CreateEditCommentDto dto) { var entity = dto.ToEntity(); var user = await _unitOfWork.UserRepository .FindAll(x => x.Id.Equals(UserId)) .Include(x => x.UserDetail) .SingleOrDefaultAsync(); entity.FullName = $"{user.UserDetail.FirstName} {user.UserDetail.LastName}"; entity.Email = UserName; entity.ProfilePictureUrl = user.UserDetail.Avatar; entity.ProfileURL = $"/Account/Settings/{user.Id}"; _unitOfWork.CommentRepository.Add(entity); await _unitOfWork.CommitAsync(); var result = entity.ToDto(); return(result); }
public static Comment ToEntity(this CreateEditCommentDto dto, Comment entity) { return(Mapper.Map(dto, entity)); }
public static Comment ToEntity(this CreateEditCommentDto dto) { return(Mapper.Map <Comment>(dto)); }
public async Task <IActionResult> Put(string id, [FromBody] CreateEditCommentDto dto) { return(Ok(await _commentService.UpdateAsync(id, dto))); }
public async Task <IActionResult> Post([FromBody] CreateEditCommentDto dto) { return(Ok(await _commentService.CreateAsync(dto))); }