public async Task <IActionResult> SetLike(string uuid) { var targetUsername = httpContextRetriever.HttpContext.User.Identity.Name; User user = await userService.GetUserByMailAsync(targetUsername); Metadata metadata = null; try { metadata = await _metadataService.GetByUuidAsync(Guid.Parse(uuid)); } catch (Exception) { throw new HttpException(HttpStatusCode.NotFound); } //Check if the user has already liked it try { var existingLike = await _likeService.GetLikeByUserAndMetadata(user, metadata); if (existingLike != null) { await _likeService.DeleteLike(existingLike); } } catch (InvalidOperationException) { var like = new Like() { LikeUser = user, Metadata = metadata }; await _likeService.SaveAsync(like); } await _unitOfWork.CompleteAsync(); return(Ok()); }