public async Task <bool> Create( LikeCreateDto model ) { var result = false; try { var exists = await _context.LikesPerPhoto.AnyAsync(x => x.UserId == model.UserId && x.PhotoId == model.PhotoId); if (!exists) { _context.LikesPerPhoto.Add(new LikesPerPhoto { PhotoId = model.PhotoId, UserId = model.UserId }); await _context.SaveChangesAsync(); } } catch (Exception e) { // Error logging } return(result); }
public async Task <bool> Create(LikeCreateDto model) { var result = false; try { var exists = await _context.LikeProduct.AnyAsync(x => x.UserId == model.UserId && x.ProductId == model.ProductId); if (!exists) { _context.LikeProduct.Add(new CLikeByProduct { UserId = model.UserId, ProductId = model.ProductId }); await _context.SaveChangesAsync(); } } catch (Exception e) { } return(result); }
public LikeConfirmationDto Update(Guid id, LikeCreateDto dto) { var post = MockData.Posts.FirstOrDefault(e => e.Id == dto.PostId); var user = MockData.Users.FirstOrDefault(e => e.Id == dto.UserId); if (post == null || user == null) { throw new LikeServiceException("User ili Post ne postoje"); } var entity = _context.Likes.FirstOrDefault(e => e.Id == id); if (entity == null) { throw new LikeServiceException("Lajk ne postoji"); } entity.LikeTipId = dto.LikeTipId; entity.PostId = dto.PostId; entity.UserId = dto.UserId; _context.SaveChanges(); _logger.Log("Update Message"); return(_mapper.Map <LikeConfirmationDto>(entity)); }
public LikeConfirmationDto Create(LikeCreateDto dto) { var post = MockData.Posts.FirstOrDefault(e => e.Id == dto.PostId); var user = MockData.Users.FirstOrDefault(e => e.Id == dto.UserId); if (post == null || user == null) { throw new LikeServiceException("User ili Post ne postoje"); } Like newEntity = new Like() { Id = Guid.NewGuid(), LikeTipId = dto.LikeTipId, PostId = dto.PostId, UserId = dto.UserId }; _context.Likes.Add(newEntity); _context.SaveChanges(); _logger.Log("Lajk kreiran"); return(_mapper.Map <LikeConfirmationDto>(newEntity)); }
public async Task <IActionResult> Create( [FromBody] LikeCreateDto model ) { return(Ok( await _likeService.Create(model) )); }
public ActionResult <LikeReadDto> Create([FromBody] LikeCreateDto likeCreateDto) { Account account = _accountRepository.Get(likeCreateDto.AccountUid); if (account == null) { return(BadRequest("Account doesnt exist")); } Like like = _mapper.Map <Like>(likeCreateDto); _likeRepository.Create(like); _logger.Log("Like created"); return(Ok(_mapper.Map <LikeReadDto>(like))); }
public ActionResult Put(Guid id, LikeCreateDto dto) { var entity = _repository.Update(id, dto); return(Ok(entity)); }
public ActionResult Post([FromBody] LikeCreateDto dto) { var entity = _repository.Create(dto); return(Ok(entity)); }