public async Task<bool> ConfirmBreweryMemberAsync(string username, NotificationDto notificationDto)
        {
            using (var context = DapperHelper.GetOpenConnection())
            {
                using (var transaction = context.BeginTransaction())
                {
                    int result = 0;
                    try
                    {
                        if (notificationDto.Value)
                        {
                            result = await context.ExecuteAsync(
                                "Update BreweryMembers set Confirmed = @Confirmed WHERE MemberUsername = @Username and BreweryId = @BreweryId",
                                new {Username = username, BreweryId = notificationDto.Id, Confirmed = true}, transaction);

                        }
                        else
                        {
                            result = await context.ExecuteAsync("DELETE FROM BreweryMembers  WHERE MemberUsername = @Username and BreweryId = @BreweryId",
                                new { Username = username, BreweryId = notificationDto.Id}, transaction);
                        }
                        transaction.Commit();
                        return result > 0;
                    }
                    catch (Exception e)
                    {
                        Log.Error(e.ToString());
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
 public async Task ConfirmBreweryMemberAsync_WrongId_Return_False()
 {
     var notification = new NotificationDto { Id = int.MaxValue, Value = true };
     var confirmed = await _userRepository.ConfirmBreweryMemberAsync("johnfredrik", notification);
     Assert.False(confirmed);
 }
 public async Task ConfirmBreweryMemberAsync_Return_False()
 {
     var notification = new NotificationDto { Id = 13, Value = false };
     var confirmed = await _userRepository.ConfirmBreweryMemberAsync("johnfredrik", notification);
     Assert.True(confirmed);
 }
 public async Task ConfirmUserBeerAsync_Return_True()
 {
     var notification = new NotificationDto {Id = 26, Value = true};
     var confirmed = await _userRepository.ConfirmUserBeerAsync("johnfredrik", notification);
     Assert.True(confirmed);
 }
        public async Task<IHttpActionResult> UpdateUserNoTifications(string username, NotificationDto notificationDto)
        {

            var changed = await _userService.UpdateNotification(username, notificationDto);
            if (!changed) return BadRequest();
            return Ok();
        }
示例#6
0
 public async Task<bool> UpdateNotification(string username, NotificationDto notificationDto)
 {
     if (notificationDto.Type == "BreweryMember")
     {
         var changed = await _userRepository.ConfirmBreweryMemberAsync(username, notificationDto);
         if (!changed) return false;
         await ReIndexUserElasticSearch(username);
         var brewery = await _breweryRepository.GetSingleAsync(notificationDto.Id, _breweryInclude);
         if (brewery == null) return false;
         var breweryDto = Mapper.Map<Brewery,BreweryDto>(brewery);
         await _breweryElasticsearch.UpdateAsync(breweryDto);
         return true;
     }
     if (notificationDto.Type == "UserBeer")
     {
         var changed = await _userRepository.ConfirmUserBeerAsync(username, notificationDto);
         if (!changed) return false;
         await ReIndexUserElasticSearch(username);
         var beer = await _beerRepository.GetSingleAsync(notificationDto.Id, _beerInclude);
         if (beer == null) return false;
         var beerDto = Mapper.Map<Beer, BeerDto>(beer);
         await _beerElasticsearch.UpdateAsync(beerDto);
         return true;
     }
     return false;
 }
示例#7
0
 public async Task<IEnumerable<NotificationDto>> GetUserNotificationsAsync(string username)
 {
     var notifications = new List<NotificationDto>();
     var memberships = _breweryRepository.GetMemberships(username);
     foreach (var membership in memberships)
     {
         if (!membership.Confirmed)
         {
             var notification = new NotificationDto
             {
                 NotificationId = membership.BreweryId,
                 Type = "New Membership",
                 Message = "Added to a new brewery"
             };
             notifications.Add(notification);
         }
     }
     var userBeers = await _userRepository.GetAllUserBeersAsync(username);
     foreach (var userBeer in userBeers)
     {
         if (!userBeer.Confirmed)
         {
             var notification = new NotificationDto
             {
                 NotificationId = userBeer.BeerId,
                 Type = "New Beer",
                 Message = "Added to a new beer"
             };
             notifications.Add(notification);
         }
     }
     return notifications;
 }