Пример #1
0
        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());
        }
Пример #2
0
        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);
        }
Пример #3
0
 public static Comment ToEntity(this CreateEditCommentDto dto, Comment entity)
 {
     return(Mapper.Map(dto, entity));
 }
Пример #4
0
 public static Comment ToEntity(this CreateEditCommentDto dto)
 {
     return(Mapper.Map <Comment>(dto));
 }
Пример #5
0
 public async Task <IActionResult> Put(string id, [FromBody] CreateEditCommentDto dto)
 {
     return(Ok(await _commentService.UpdateAsync(id, dto)));
 }
Пример #6
0
 public async Task <IActionResult> Post([FromBody] CreateEditCommentDto dto)
 {
     return(Ok(await _commentService.CreateAsync(dto)));
 }