Exemplo n.º 1
0
        public async Task <IActionResult> Handle(GetSpeakersInEventQuery request, CancellationToken cancellationToken)
        {
            var speakers = _context.Attendances.Include(x => x.Member).Where(x => x.EventId == request.Id
                                                                             &&
                                                                             x.Speaker)
                           .Cacheable()
                           .ToList()
                           .Select(x => new GetSpeakersInEventInEventResponse
            {
                Member = _mapper.Map <MemberDetailViewModel>(x.Member)
            })
                           .ToList();

            if (!speakers.Any())
            {
                return(HttpResponseCodeHelper.NotContent());
            }

            return(HttpResponseCodeHelper.Ok(speakers));
        }
        public async Task <IActionResult> Handle(SearchMemberQuery request, CancellationToken cancellationToken)
        {
            var members = _context.Members.Where(x => x.Email.Contains(request.Query)
                                                 ||
                                                 x.FirstName.Contains(request.Query)
                                                 ||
                                                 x.LastName.Contains(request.Query)
                                                 ||
                                                 x.MeetupId.ToString().Contains(request.Query))
                          .Cacheable()
                          .Take(10)
                          .AsNoTracking();

            if (!members.Any())
            {
                return(HttpResponseCodeHelper.NotFound());
            }

            return(HttpResponseCodeHelper.Ok(_mapper.Map <List <MemberDetailViewModel> >(members)));
        }
        public async Task <IActionResult> Handle(AddMemberCommand request, CancellationToken cancellationToken)
        {
            var memberToCheck = await _context.Members.FirstOrDefaultAsync(x => x.Email.ToUpper() == request.Email.ToUpper()
                                                                           ||
                                                                           request.MeetupId != null?x.MeetupId == request.MeetupId : true);

            if (memberToCheck != null)
            {
                return(HttpResponseCodeHelper.Conflict("Ya se encuentra un usuario registrado con ese email"));
            }

            var member = _mapper.Map <Member>(request);

            member.Role = UserRole.Member;
            await _context.Members.AddAsync(member);

            await _context.SaveChangesAsync();


            return(HttpResponseCodeHelper.Ok(_mapper.Map <MemberDetailViewModel>(member)));
        }
        public async Task <IActionResult> Handle(GetAttendeesQuery request, CancellationToken cancellationToken)
        {
            var query = _context.Attendances
                        .Include(x => x.Member)
                        .ThenInclude(s => s.Events)
                        .Where(x => x.EventId == request.EventId);

            if (request.MemberId != null)
            {
                query = query.Where(x => request.MemberId.Value == x.MemberId);
            }

            if (!string.IsNullOrWhiteSpace(request.Query))
            {
                query = query.Where(x => x.Member.Email.Contains(request.Query)
                                    ||
                                    x.Member.FirstName.Contains(request.Query)
                                    ||
                                    x.Member.LastName.Contains(request.Query)
                                    ||
                                    x.Member.MeetupId.ToString().Contains(request.Query));
            }

            var attendees = await query.Select(s => _mapper.Map <AttendantViewModel>(s))
                            .ToListAsync(cancellationToken: cancellationToken);



            if (attendees == null || !attendees.Any())
            {
                return(HttpResponseCodeHelper.NotContent());
            }

            if (attendees.Count == 1 && request.MemberId != null)
            {
                return(HttpResponseCodeHelper.Ok(attendees.First()));
            }
            return(HttpResponseCodeHelper.Ok(attendees));
        }
        public async Task <IActionResult> Handle(SendPushNotificationsCommand request, CancellationToken cancellationToken)
        {
            var pushNotificationToSend = _mapper.Map <PushNotification>(request);

            foreach (var notification in request.PushNotificationIds)
            {
                DefaultContractResolver contractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                };
                pushNotificationToSend.To = notification;
                var pushNotification = await "https://fcm.googleapis.com/fcm".AppendPathSegment("send")
                                       .WithHeader("Authorization", "key=AAAAp6mIFl8:APA91bGoewvoSfIbLcHFL4OCxPa19drL-pWuQ5YYpsGh3gh_xdWLyZTS2F3pwpUJpMPWPiIpkJTq0oPbIomCCpG3zFTEutxDJGJT703uebKnTCFnYe9GcqzIuFURQwYueOIW6eINonjY")
                                       .PostAsync(new StringContent(JsonConvert.SerializeObject(pushNotificationToSend, new JsonSerializerSettings
                {
                    ContractResolver = contractResolver,
                    Formatting       = Formatting.Indented
                }), Encoding.UTF8, "application/json"))
                                       .ReceiveJson();
            }

            return(HttpResponseCodeHelper.NotContent());
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Handle(AddAttendeeCommand request, CancellationToken cancellationToken)
        {
            var @event = await _context.Events.Include(x => x.Attendees)
                         .FirstOrDefaultAsync(x => x.Id == request.IdEvent);

            if (@event == null)
            {
                return(HttpResponseCodeHelper.Error("El evento indicado no existe"));
            }

            var member = await _context.Members.FirstOrDefaultAsync(x => x.Id == request.IdMember);

            if (member == null)
            {
                return(HttpResponseCodeHelper.Error("El miembro indicado no existe"));
            }

            @event.AddAttendance(member, AttendanceRegisterType.CurrentEvent);

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.NotContent());
        }
        public async Task <IActionResult> Handle(GetBadgeQuery request, CancellationToken cancellationToken)
        {
            var badgesFromUser = await _context.Badges.Where(x => (request.BadgeId != null ? x.Id == request.BadgeId : true))
                                 .Cacheable()
                                 .AsNoTracking()
                                 .ToListAsync();

            if (!badgesFromUser.Any())
            {
                return(HttpResponseCodeHelper.NotContent());
            }

            var badgeToReturn = _mapper.Map <List <BadgeDetailViewModel> >(badgesFromUser);

            if (request.BadgeId != null)
            {
                return(HttpResponseCodeHelper.Ok(badgeToReturn.First()));
            }
            else
            {
                return(HttpResponseCodeHelper.Ok(badgeToReturn));
            }
        }
        public async Task <IActionResult> Handle(MakeRaffleCommand request, CancellationToken cancellationToken)
        {
            var members = _context.GroupCodes.Include(s => s.Members).ThenInclude(s => s.Member)
                          .Where(x => x.Id == request.GroupCodeId)
                          .SelectMany(x => x.Members.Where(s =>
                                                           request.RepeatWinners ? s.Winner : !s.Winner))
                          .ToList()
                          .OrderBy(s => new Random().Next())
                          .Take(request.CountOfWinners)
                          .ToList();
            var maxWinnerPisition = await _context.GroupCodeMembers.OrderByDescending(x => x.WinnerPosition).Take(1).Select(x => x.WinnerPosition).FirstOrDefaultAsync(cancellationToken: cancellationToken);

            var count = request.CountOfWinners > members.Count ? members.Count : request.CountOfWinners;

            for (int i = 0; i < count; i++)
            {
                members[i].SetAsWinner(++maxWinnerPisition);
            }

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.Ok(_mapper.Map <List <MemberDetailViewModel> >(members.Select(s => s.Member))));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Handle(UpdateMeCommand request, CancellationToken cancellationToken)
        {
            var currentMemberId = currentUser.User.Id;
            var member          = await _context.Members.FirstOrDefaultAsync(x => x.Id == currentMemberId);

            _mapper.Map(request, member);


            if (request.ImageFile != null)
            {
                var fileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(request.ImageFile.FileName)}";
                var response = await filesServices.UploadAsync(request.ImageFile.OpenReadStream(), fileName, Container.Members);

                if (!string.IsNullOrEmpty(member.PictureName))
                {
                    await filesServices.DeleteAsync(member.PictureName, Container.Members);
                }
                member.SetFile(response.FileUri, response.Name);
            }

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.Ok(_mapper.Map(member, new MemberDetailViewModel())));
        }
        public async Task <IActionResult> Handle(UpdateSponsorCommand request, CancellationToken cancellationToken)
        {
            var sponsor = await _context.Sponsors.FirstOrDefaultAsync(x => x.Id == request.Id);

            if (sponsor == null)
            {
                return(HttpResponseCodeHelper.NotFound());
            }
            _mapper.Map(request, sponsor);

            if (request.ImageFile != null)
            {
                var fileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(request.ImageFile.FileName)}";
                var response = await filesServices.UploadAsync(request.ImageFile.OpenReadStream(), fileName, Container.Sponsors);

                await filesServices.DeleteAsync(sponsor.LogoFileName, Container.Sponsors);

                sponsor.SetFile(response.FileUri, response.Name);
            }

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.Ok(_mapper.Map <Sponsor>(sponsor)));
        }
        public async Task <IActionResult> Handle(AddCurrentUserToGroupCodeCommand request, CancellationToken cancellationToken)
        {
            var groupCode = await _context.GroupCodes.FirstOrDefaultAsync(x => x.Event.Id == request.EventId
                                                                          &&
                                                                          x.Code.ToUpper() == request.Code.ToUpper());

            if (groupCode == null)
            {
                return(HttpResponseCodeHelper.NotFound("El Grupo de codigo no existe"));
            }

            if (groupCode.Code.ToUpper() != request.Code.ToUpper())
            {
                return(HttpResponseCodeHelper.NotFound("El código ingresado es incorrecto"));
            }

            var memberInEvent = await _context.Events.AnyAsync(x => x.Id == groupCode.EventId
                                                               &&
                                                               x.GroupCodes.Any(g => g.Code == request.Code)
                                                               &&
                                                               x.Attendees.Any(a =>
                                                                               a.MemberId == _currentUser.User.Id));

            if (!memberInEvent)
            {
                return(HttpResponseCodeHelper.Error("El miembro logueado no se encuentra registrado en el evento al cual pertenece el codigo"));
            }

            var member = await _context.Members.FirstOrDefaultAsync(x => x.Id == _currentUser.User.Id);

            groupCode.AddMember(member, request.Code);

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.Ok(_mapper.Map <AddCurrentUserToGroupCodeCommand.Response>(groupCode)));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Handle(AuthEventBriteCommand request, CancellationToken cancellationToken)
        {
            var dict = new Dictionary <string, string>
            {
                { "client_id", _eventMonitor.CurrentValue.ClientId },
                { "client_secret", _eventMonitor.CurrentValue.ClientSecret },
                { "grant_type", "authorization_code" },
                { "code", request.Token },
                { "redirect_uri", _eventMonitor.CurrentValue.RedirectUrl },
            };
            var req = new HttpRequestMessage(HttpMethod.Post, _eventMonitor.CurrentValue.UrlToken)
            {
                Content = new FormUrlEncodedContent(dict)
            };
            var result = await _client.SendAsync(req, cancellationToken);

            if (result.IsSuccessStatusCode)
            {
                var response = await result.Content.ReadAsAsync <EventBriteToken>();

                _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {response.AccessToken}");
                var res = await _client.GetAsync($"{_eventMonitor.CurrentValue.Url}/users/me/?expand=assortment");


                if (res.IsSuccessStatusCode)
                {
                    var value = await res.Content.ReadAsAsync <EventBriteMe>();

                    var user = await _userService.AuthenticateOrCreateEventbrite(value);

                    return(HttpResponseCodeHelper.Ok(user));
                }
            }

            return(HttpResponseCodeHelper.Error());
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Handle(NewSponsorCommand request, CancellationToken cancellationToken)
        {
            var newSponsor = _mapper.Map <Sponsor>(request);

            if (request.ImageFile != null)
            {
                var fileName   = $"{Guid.NewGuid().ToString()}{Path.GetExtension(request.ImageFile.FileName)}";
                var logoUplaod = await filesServices.UploadAsync(request.ImageFile.OpenReadStream(), fileName, Container.Sponsors);

                if (logoUplaod == null)
                {
                    return(HttpResponseCodeHelper.NotFound());
                }

                newSponsor.SetFile(logoUplaod.FileUri, logoUplaod.Name);
                await _context.Sponsors.AddAsync(newSponsor);
            }

            await _context.SaveChangesAsync();

            var mapped = _mapper.Map <SponsorDetailViewModel>(newSponsor);

            return(HttpResponseCodeHelper.Ok(mapped));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Handle(CompleteEventCommand request, CancellationToken cancellationToken)
        {
            var eventToUpdate = await _context.Events.Include(x => x.Attendees)
                                .ThenInclude(x => x.Member)
                                .FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);

            if (eventToUpdate == null)
            {
                return(HttpResponseCodeHelper.NotFound());
            }

            Badge badge = default;

            if (request.GiveBadgeToAttendees)
            {
                badge = await _context.Badges.FirstOrDefaultAsync(x => x.Id == request.BadgeId, cancellationToken : cancellationToken);
            }

            eventToUpdate.Complete(request, badge);

            await _context.SaveChangesAsync(cancellationToken);

            return(HttpResponseCodeHelper.NotContent());
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Handle(RemoveMaterialCommand request, CancellationToken cancellationToken)
        {
            var @event = await _context.Events.Include(x => x.Attendees)
                         .FirstOrDefaultAsync(x => x.Id == request.EventId);

            if (@event == null)
            {
                return(HttpResponseCodeHelper.Error("El evento indicado no existe"));
            }


            var material = await _context.Materials.FirstOrDefaultAsync(x => x.Id == request.MaterialId);

            if (material == null)
            {
                return(HttpResponseCodeHelper.Error("El Material indicado no existe"));
            }

            @event.RemoveMaterial(material);

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.NotContent());
        }
        public async Task <IActionResult> Handle(AssignMemberToBadgeCommand request, CancellationToken cancellationToken)
        {
            var membersAlreadyHasTheBadge =
                _context.BadgeMembers.Any(x => x.BadgeId == request.BadgeId && x.MemberId == request.MemberId);

            if (membersAlreadyHasTheBadge)
            {
                return new ObjectResult("El miembro que esta intentando asignar ya tiene ese Badge")
                       {
                           StatusCode = 409
                       }
            }
            ;;

            var badge = await _context.Badges.FirstOrDefaultAsync(x => x.Id == request.BadgeId);

            if (badge == null)
            {
                return(HttpResponseCodeHelper.NotFound("No se encontro el Badge"));
            }
            var member = await _context.Members.FirstOrDefaultAsync(x => x.Id == request.MemberId
                                                                    &&
                                                                    !x.Badges.Any(b => b.BadgeId == request.BadgeId));

            if (member == null)
            {
                return(HttpResponseCodeHelper.NotFound("No se encontro el miembro"));
            }

            member.AssignBadge(badge);

            await _context.SaveChangesAsync();

            return(new StatusCodeResult(204));
        }
    }
        public async Task <IActionResult> Handle(RemoveEventInformationCommand request, CancellationToken cancellationToken)
        {
            var @event = await _context.Events.Include(x => x.Attendees)
                         .FirstOrDefaultAsync(x => x.Id == request.EventId);

            if (@event == null)
            {
                return(HttpResponseCodeHelper.Error("El evento indicado no existe"));
            }


            var eventInformation = await _context.EventInformation.FirstOrDefaultAsync(x => x.Id == request.EventInformationId);

            if (eventInformation == null)
            {
                return(HttpResponseCodeHelper.Error("La información que intenga eliminar, no existe"));
            }

            @event.RemoveInformation(eventInformation);

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.NotContent());
        }
        public async Task <IActionResult> Handle(GetEventLiveDetailQuery request, CancellationToken cancellationToken)
        {
            var eventToReturn = _context.Events
                                .Include(x => x.GroupCodes)
                                .ThenInclude(x => x.Members)
                                .Where(x => x.Id == request.Id
                                       &&
                                       x.Live)
                                .Cacheable()
                                .FirstOrDefault();

            if (eventToReturn == null)
            {
                return(HttpResponseCodeHelper.NotFound());
            }

            var eventViewModel = _mapper.Map <GetEventLiveDetailQuery.Response>(eventToReturn);

            if (eventToReturn == null)
            {
                return(HttpResponseCodeHelper.NotFound());
            }
            if (_currentUser.IsLoggued)
            {
                //TODO: Refactor
                if (_currentUser.User.Rol == UserRole.Member)
                {
                    eventViewModel.GroupCodes = null;
                }
                eventViewModel.GeneralAttendance = eventToReturn.GeneralAttended &&
                                                   (_currentUser.User.Rol == UserRole.Admin
                                                    ||
                                                    _currentUser.User.Rol == UserRole.Organizer)
                    ? new GetEventLiveDetailQuery.Response.ReportGeneralAttendance
                {
                    TokenToReportGeneralAttendance =
                        _attendanceService.GetTokenToReportGeneralAttendance(eventToReturn),
                    GeneralAttendedCode = eventToReturn.GeneralAttendedCode
                }
                    : new GetEventLiveDetailQuery.Response.ReportGeneralAttendance();
                eventViewModel.TokenToReportMyAttendance = _attendanceService.GetTokenToReportMyAttendance(eventToReturn);


                if (eventToReturn == null)
                {
                    return(HttpResponseCodeHelper.NotContent());
                }
                var countAttended = _context.Events.Where(x => x.Id == request.Id)
                                    .Select(s => Tuple.Create(s.Attendees.Count, s.Attendees.Count(k => k.Attended)))
                                    .FirstOrDefault();

                eventViewModel.Attended = await _context.Attendances.AnyAsync(a => a.EventId == request.Id
                                                                              &&
                                                                              a.MemberId == _currentUser.User.Id
                                                                              &&
                                                                              a.Attended);

                eventViewModel.MembersDetails = new GetEventLiveDetailQuery.Response.Members
                {
                    TotalMembersRegistered        = countAttended.Item1,
                    TotalMembersAttended          = countAttended.Item2,
                    EstimatedAttendancePercentage = eventToReturn.EstimatedAttendancePercentage
                };
                eventViewModel.MembersDetails.MembersAttended = await _context.Attendances.Include(x => x.Member).Where(x => x.EventId == eventViewModel.Id
                                                                                                                        &&
                                                                                                                        x.Attended)
                                                                .OrderByDescending(x => x.AttendedTime)
                                                                .Take(8)
                                                                .Select(s => _mapper.Map <GetEventLiveDetailQuery.Response.MemberDetail>(s.Member)).ToListAsync(cancellationToken: cancellationToken);
            }
            if (request.Id != null)
            {
                return(HttpResponseCodeHelper.Ok(eventViewModel));
            }
            return(HttpResponseCodeHelper.Ok(eventViewModel));
        }