public async Task <ServiceResponseDto> MarkSharedMemeAsSeenAsync(SharedMemeDto sharedMeme) { ServiceResponseDto sharedMemeMarkAsSeenDto = new ServiceResponseDto { Message = "Something happened try again later.." }; if (!await _sharedMemeRepository.ExistsAsync(sm => sm.Id.Equals(sharedMeme.Id))) { sharedMemeMarkAsSeenDto.Message = "Something happened try again later.."; return(sharedMemeMarkAsSeenDto); } SharedMeme sharedMemeEntity = await _sharedMemeRepository.FindSingleByExpressionAsync(sm => sm.Id.Equals(sharedMeme.Id)); if (sharedMemeEntity.IsSeen) { sharedMemeMarkAsSeenDto.Message = "The shared meme is already marked as seen."; return(sharedMemeMarkAsSeenDto); } sharedMemeEntity.IsSeen = true; if (!await _sharedMemeRepository.UpdateAsync(sharedMemeEntity)) { return(sharedMemeMarkAsSeenDto); } sharedMemeMarkAsSeenDto.Success = true; sharedMemeMarkAsSeenDto.Message = "Successfully marked the shared meme as seen."; return(sharedMemeMarkAsSeenDto); }
public async Task GetSharedMemesAsync_Should_Pass() { // Arrange SharedMemeDto sharedMemeDto1 = new SharedMemeDto { SenderUserId = 1, ReceiverUserId = 2, MemeId = "a0Q558q" }; SharedMemeDto sharedMemeDto2 = new SharedMemeDto { SenderUserId = 1, ReceiverUserId = 2, MemeId = "a0QQZoL" }; await MemeSharingService.ShareMemeToMutualFollowerAsync(sharedMemeDto1); await MemeSharingService.ShareMemeToMutualFollowerAsync(sharedMemeDto2); // Act List <SharedMeme> sharedMemes = (List <SharedMeme>) await SharedMemeRepository.FindManyByExpressionAsync(sharedMeme => sharedMeme.ReceiverUserId.Equals(2)); // Assert Assert.IsTrue(sharedMemes.TrueForAll(sharedMeme => sharedMeme.MemeId.Equals("a0Q558q") || sharedMeme.MemeId.Equals("a0QQZoL"))); }
public async Task <IActionResult> MarkMemeAsSeenAsync([FromBody] MarkMemeAsSeenViewModel markMemeAsSeenViewModel) { if (!ModelState.IsValid) { return(Json(ModelState.DefaultInvalidModelStateWithErrorMessages())); } int userId = Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier)); SharedMemeDto sharedMemeDto = markMemeAsSeenViewModel.GetSharedMemeDto(userId); ServiceResponseDto sharedMemeMarkAsSeenDto = await _memeSharingService.MarkSharedMemeAsSeenAsync(sharedMemeDto); return(Json(sharedMemeMarkAsSeenDto)); }
public async Task <IActionResult> ShareMemeToFriendAsync([FromBody] ShareMemeViewModel shareMemeViewModel) { if (!ModelState.IsValid) { return(Json(ModelState.DefaultInvalidModelStateWithErrorMessages())); } int userId = Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier)); SharedMemeDto sharedMemeDto = shareMemeViewModel.GetSharedMemeDto(userId); ServiceResponseDto sharedMemeResultDto = await _memeSharingService.ShareMemeToMutualFollowerAsync(sharedMemeDto); return(sharedMemeResultDto.Success ? Json(new { success = true, to = sharedMemeResultDto.Message }) : Json(new { success = false, message = "Something happened.." })); }
public async Task ShareMemeToMutualFollowerAsync_Should_Pass() { // Arrange SharedMemeDto sharedMemeDto = new SharedMemeDto { SenderUserId = 1, ReceiverUserId = 2, MemeId = "a0Q558q" }; // Act ServiceResponseDto serviceResponseDto = await MemeSharingService.ShareMemeToMutualFollowerAsync(sharedMemeDto); // Assert Assert.IsTrue(serviceResponseDto.Success); }
public async Task <ServiceResponseDto> ShareMemeToMutualFollowerAsync(SharedMemeDto sharedMemeDto) { SharedMeme sharedMeme = DtoToEntityConverter.Convert <SharedMeme, SharedMemeDto>(sharedMemeDto); string username = (await _userRepository.FindSingleByExpressionAsync(user => user.Id.Equals(sharedMeme.ReceiverUserId))).UserName; if (await _sharedMemeRepository.CreateAsync(sharedMeme)) { return new ServiceResponseDto { Message = username, Success = true } } ; return(new ServiceResponseDto { Message = username, Success = false }); } }