public async Task <Like> AddLike(int userId, int recipientId) { if (userId != int.Parse(httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value)) { throw new Exception("UnAuthorized.!!"); } var getLike = await likeDal.Get(u => u.LikerId == userId && u.LikeeId == recipientId); if (getLike != null) { throw new Exception("You already like this profiles.!!"); } var getLikeesUserFromRepo = await userDal.Get(u => u.Id == recipientId); if (getLikeesUserFromRepo == null) { throw new Exception("Not found that user you want to like.!!"); } getLike = new Like { LikerId = userId, LikeeId = recipientId }; var addLikeToDb = await likeDal.Add(getLike); if (addLikeToDb == null) { throw new Exception("Failed to like user.!!"); } return(addLikeToDb); }
public IDataResult <Like> GetById(int id) { var selectedLike = _likeDal.Get(l => l.Id == id); IResult result = BusinessRule.Run ( CheckIfLikeExist(id), _userService.CheckIfUserExist(selectedLike.UserId), _videoService.CheckIfVideoExist(selectedLike.VideoId) ); if (result != null) { return(new ErrorDataResult <Like>(result.Message)); } return(new SuccessDataResult <Like>(selectedLike)); }
public Like GetLikeById(int likeId) { return(_likeDal.Get(x => x.LikeId == likeId)); }
public bool GetIsUserLike(int photoId, int userId) { var result = _likeDal.Get(like => like.UserId == userId && like.PhotoId == photoId); return(result != null); }