Exemple #1
0
        public async Task ProcessAttendees(Event eventToSync)
        {
            if (eventToSync.Platform != EventPlatform.Meetup)
            {
                return;
            }
            var meetupAttendees = await _meetupServices.GetAttendees(int.Parse(eventToSync.EventId));

            var meetupAttendeesIds = meetupAttendees.Select(s => s.Member.Id);
            var attendeesToEach    = await _context.Attendances.Include(x => x.Member).Where(x =>
                                                                                             x.EventId == eventToSync.Id
                                                                                             &&
                                                                                             meetupAttendeesIds.Contains(x.Member.MeetupId)).ToListAsync();

            foreach (var attende in meetupAttendees)
            {
                var attendace = attendeesToEach?.FirstOrDefault(x => x.Member.MeetupId == attende.Member.Id);
                if (attendace == null)
                {
                    if (attende.Member.Id != 0)
                    {
                        var newMember = await _context.Members.Where(x => x.MeetupId == attende.Member.Id).FirstOrDefaultAsync();

                        if (newMember == null)
                        {
                            newMember = new Member
                            {
                                MeetupId  = attende.Member.Id,
                                FirstName = attende.Member.Name,
                                Picture   = attende.Member.Photo?.HighresLink?.AbsolutePath == null ? "" :
                                            attende.Member.Photo?.HighresLink?.AbsoluteUri,
                                Role      = UserRole.Member,
                                Biography = attende.Member.Bio
                            }
                        }
                        ;
                        attendace = SetState(attende,
                                             new Attendance(newMember, eventToSync, AttendanceRegisterType.ExternalPage));

                        await _context.Attendances.AddAsync(attendace);
                    }
                }
                else
                {
                    attendace = SetState(attende, attendace);
                }
            }
            await _context.SaveChangesAsync();

            var percent = _context.Members.Count(x => meetupAttendeesIds.Contains(x.MeetupId)
                                                 &&
                                                 (x.Events.Any(a => !a.DoNotKnow) && x.Events.Count(s => s.Attended) * 100 /
                                                  x.Events.Count(a => !a.DoNotKnow) > 60));

            if (meetupAttendeesIds.Any())
            {
                eventToSync.EstimatedAttendancePercentage = ((decimal)percent * 100) / meetupAttendeesIds.Count();
            }
            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Handle(InformAttendancesCommand request, CancellationToken cancellationToken)
        {
            var eventToUpdate = await _context.Events.Include(x => x.Attendees).FirstOrDefaultAsync(x => x.Id == request.EventId);

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

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

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

            var attendance = eventToUpdate.AddAttendance(member, AttendanceRegisterType.CurrentEvent);

            if (request.Attended)
            {
                attendance.Attend();
            }
            else
            {
                attendance.NoAttend();
            }

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.NotContent());
        }
        public async Task <IActionResult> Handle(DeleteMemberToGroupCodeCommand request, CancellationToken cancellationToken)
        {
            var groupCode = await _context.GroupCodes.Include(x => x.Members).FirstOrDefaultAsync(x => x.Event.Id == request.EventId
                                                                                                  &&
                                                                                                  x.Id == request.GroupCodeId);

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


            var memberInEvent = await _context.Events.AnyAsync(x => x.Id == groupCode.EventId
                                                               &&
                                                               x.GroupCodes.Any(g => g.Id == request.GroupCodeId)
                                                               &&
                                                               x.Attendees.Any(a =>
                                                                               a.MemberId == request.MemberId), cancellationToken : cancellationToken);

            if (!memberInEvent)
            {
                return(HttpResponseCodeHelper.Error("El miembro que intenta eliminar del código no existe"));
            }

            var member = await _context.Members.FirstOrDefaultAsync(x => x.Id == request.MemberId, cancellationToken : cancellationToken);

            groupCode.RemoveMember(member);

            await _context.SaveChangesAsync(cancellationToken);

            return(HttpResponseCodeHelper.NotContent());
        }
        public async Task <IActionResult> Handle(AddMemberToGroupCodeCommand request, CancellationToken cancellationToken)
        {
            var groupCode = await _context.GroupCodes.Include(x => x.Members).FirstOrDefaultAsync(x => x.Event.Id == request.EventId
                                                                                                  &&
                                                                                                  x.Id == request.GroupCodeId);

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


            var memberInEvent = await _context.Events.Include(x => x.Attendees).FirstOrDefaultAsync(x => x.Id == groupCode.EventId
                                                                                                    &&
                                                                                                    x.GroupCodes.Any(g => g.Id == request.GroupCodeId)
                                                                                                    &&
                                                                                                    x.Attendees.Any(a =>
                                                                                                                    a.MemberId == request.MemberId));

            if (memberInEvent == null)
            {
                return(HttpResponseCodeHelper.Error("El miembro que intenta agregar código"));
            }

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

            memberInEvent.Attended(member, AttendanceRegisterType.CurrentEvent);

            groupCode.AddMember(member);

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.Ok(_mapper.Map <AddMemberToGroupCodeCommand.Response>(groupCode)));
        }
        public async Task Process()
        {
            var eventBriteEvents = await _eventBriteServices.GetEvents();

            var minesFromEventBrite = _context.Events.Where(x => x.Platform == EventPlatform.EventBrite).Select(x => x.EventId)
                                      .ToList();

            var eventEventBriteProcesseds = eventBriteEvents.Aggregate(new List <Event>(), (list, @event) =>
            {
                if (!minesFromEventBrite.Any(x => x == @event.Id))
                {
                    list.Add(new Event
                    {
                        Description = @event.Description.Text,
                        Title       = @event.Name.Text,
                        Url         = @event.Url,
                        EventId     = @event.Id.ToString(),
                        Date        = @event.Start.Utc.Date,
                        ImageUrl    = @event.Logo?.Original?.Url?.OriginalString,
                        Platform    = EventPlatform.EventBrite
                    });
                }
                return(list);
            });

            _context.Events.AddRange(eventEventBriteProcesseds);

            await _context.SaveChangesAsync();

            foreach (var eventBriteProcessed in eventEventBriteProcesseds)
            {
                await _syncServices.SyncEvent(eventBriteProcessed.Id);
            }
        }
        public async Task <IActionResult> Handle(PutCheckAttendanceByCodeCommand request, CancellationToken cancellationToken)
        {
            var eventToCheck = _context.Events.Any(x => x.Id == request.EventId
                                                   &&
                                                   x.GeneralAttended
                                                   &&
                                                   x.GeneralAttendedCode == request.Code);

            if (!eventToCheck)
            {
                return(HttpResponseCodeHelper.NotFound());
            }

            var memberId = _currentUser.User.Id;

            var eventToAdd = _context.Attendances.FirstOrDefault(x => x.EventId == request.EventId
                                                                 &&
                                                                 x.MemberId == memberId);

            if (eventToAdd == null)
            {
                eventToAdd = new Attendance(memberId, request.EventId, AttendanceRegisterType.CurrentEvent);
                await _context.Attendances.AddAsync(eventToAdd);
            }
            eventToAdd.Attend();
            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.Ok(new CheckAttendanceGeneralResponse(request.EventId)));
        }
        public async Task <IActionResult> Handle(AssignBadgeToAttendancesInGroupCodeCommand request, CancellationToken cancellationToken)
        {
            var badge = await _context.Badges.FirstOrDefaultAsync(x => x.Id == request.BadgeId);

            if (badge == null)
            {
                return(HttpResponseCodeHelper.NotFound("El badge que esta intentando asignar no se encuentra en el sistema"));
            }

            var groupCode = await _context.GroupCodes.Include(s => s.Members)
                            .ThenInclude(x => x.Member)
                            .ThenInclude(x => x.Badges)
                            .Include(x => x.GroupCodeBadges)
                            .ThenInclude(x => x.Badge)
                            .Where(x => x.Id == request.GroupCodeId)
                            .FirstOrDefaultAsync();

            if (groupCode == null)
            {
                return(HttpResponseCodeHelper.NotFound("El badge que esta intentando asignar no se encuentra en el sistema"));
            }

            var response = groupCode.AssignBadge(badge);

            if (!response.SuccessResult)
            {
                return(HttpResponseCodeHelper.Error(response.Errors.First()));
            }

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.NotContent());
        }
        public async Task <IActionResult> Handle(DeleteTemplateCommand request, CancellationToken cancellationToken)
        {
            var templateToDelete = await _context.Templates.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);

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

            var anyEvent = await _context.Events.AnyAsync(x => x.EmailTemplateThanksSpeakers == templateToDelete
                                                          ||
                                                          x.EmailTemplateThanksAttended == templateToDelete
                                                          ||
                                                          x.EmailTemplateThanksSponsors == templateToDelete);

            if (anyEvent)
            {
                return(HttpResponseCodeHelper.Conflict(
                           "El template que intenta eliminar se encuentra asociado a uno o mas eventos."));
            }

            _context.Templates.Remove(templateToDelete);
            await _context.SaveChangesAsync(cancellationToken);

            return(HttpResponseCodeHelper.NotContent());
        }
Exemple #9
0
        public async Task <IActionResult> UpdateMember(int id, Member member)
        {
            member.Id = id;
            if (member.Organized)
            {
                member.Role = UserRole.Organizer;
            }
            else
            {
                member.Role = UserRole.Member;
            }
            _context.Entry(member).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(Ok(member));
        }
Exemple #10
0
        public async Task <IActionResult> Handle(NewBadgeGroupCommand request, CancellationToken cancellationToken)
        {
            await _context.BadgeGroups.AddAsync(_mapper.Map(request, new BadgeGroup()));

            await _context.SaveChangesAsync();

            return(new StatusCodeResult(204));
        }
Exemple #11
0
        public async Task <IActionResult> Handle(UpdateBadgeCommand request, CancellationToken cancellationToken)
        {
            var badge = await _context.Badges.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);

            if (badge == null)
            {
                return(new StatusCodeResult(404));
            }
            _mapper.Map(request, badge);


            if (request.ImageFiles != null)
            {
                foreach (var item in request.ImageFiles)
                {
                    if (item.Headers["BadgeType"] == BadgeImageName.SimpleBadge.ToString() ||
                        item.FileName == BadgeImageName.SimpleBadge.ToString())
                    {
                        var badgeCreateResponse = await badgesServices.ReplaceAsync(item, badge.SimpleImageName);

                        if (badgeCreateResponse == null)
                        {
                            return(new StatusCodeResult(400));
                        }
                        badge.SimpleImageName = badgeCreateResponse.FileDetail.Name;
                        badge.SimpleImageUrl  = badgeCreateResponse.FileDetail.FileUri.AbsoluteUri;
                    }
                    else if (item.Headers["BadgeType"] == BadgeImageName.Badge.ToString() ||
                             item.FileName == BadgeImageName.Badge.ToString())
                    {
                        var badgeCreateResponse = await badgesServices.ReplaceAsync(item, badge.ImageName);

                        if (badgeCreateResponse == null)
                        {
                            return(new StatusCodeResult(400));
                        }
                        badge.ImageName = badgeCreateResponse.FileDetail.Name;
                        badge.ImageUrl  = badgeCreateResponse.FileDetail.FileUri.AbsoluteUri;
                    }
                    else if (item.Headers["BadgeType"] == BadgeImageName.LinkedinBadge.ToString() ||
                             item.FileName == BadgeImageName.LinkedinBadge.ToString())
                    {
                        var badgeCreateResponse = await badgesServices.CreateAsync(item);

                        if (badgeCreateResponse == null)
                        {
                            return(new StatusCodeResult(400));
                        }
                        badge.LinkedinImageName = badgeCreateResponse.FileDetail.Name;
                        badge.LinkedinImageUrl  = badgeCreateResponse.FileDetail.FileUri.AbsoluteUri;
                    }
                }
            }

            await _context.SaveChangesAsync();

            return(new StatusCodeResult(204));
        }
        public async Task <IActionResult> Handle(PutReportAttendanceCommand request, CancellationToken cancellationToken)
        {
            var response   = attendanceService.ValidateTokenToReportMyAttendance(request.Token);
            var eventToAdd = _context.Events.Include(x => x.Attendees).FirstOrDefault(x => x.Id == response.EventId);
            var member     = _context.Members.FirstOrDefault(x => x.Id == response.UserId);

            eventToAdd.Attended(member, AttendanceRegisterType.CurrentEvent);
            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.Ok(new PutReportAttendanceCommand.Response(eventToAdd.Id, member.Id)));
        }
        public async Task <IActionResult> Handle(NewTemplateCommand request, CancellationToken cancellationToken)
        {
            var newTemplate = _mapper.Map <Template>(request);
            await _context.Templates.AddAsync(newTemplate);

            await _context.SaveChangesAsync();

            var mapped = _mapper.Map <TemplateViewModel>(newTemplate);

            return(HttpResponseCodeHelper.Ok(mapped));
        }
Exemple #14
0
        public async Task <IActionResult> Handle(DeleteSponsorCommand request, CancellationToken cancellationToken)
        {
            var sponsorToDelete = await _context.Sponsors.FirstOrDefaultAsync(x => x.Id == request.Id);

            if (sponsorToDelete == null)
            {
                return(HttpResponseCodeHelper.NotFound());
            }
            _context.Sponsors.Remove(sponsorToDelete);
            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.NotContent());
        }
        public async Task <IActionResult> Handle(UpdateAttendeeCommand request, CancellationToken cancellationToken)
        {
            var attendee = await _context.Attendances
                           .Include(x => x.Member)
                           .FirstOrDefaultAsync(x => x.EventId == request.EventId
                                                &&
                                                x.MemberId == request.MemberId);

            if (attendee == null)
            {
                attendee = new Attendance(request.MemberId, request.EventId, AttendanceRegisterType.CurrentEvent);
                _context.Attendances.Add(attendee);
            }
            if (request?.Attended == true)
            {
                attendee.Attend();
            }
            else if (request?.Attended == false)
            {
                attendee.NoAttend();
            }

            if (request?.Speaker == true)
            {
                attendee.SetSpeaker();
            }
            else if (request?.Speaker == false)
            {
                attendee.RemoveSpeaker();
            }



            if (request?.NotifiedAbsence == true)
            {
                attendee.NotifyAbsence();
            }

            if (request?.Organizer == true)
            {
                attendee.SetOrganizer();
            }
            else if (request?.Organizer == false)
            {
                attendee.RemoveOrganizer();
            }

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.Ok(_mapper.Map <AttendantViewModel>(attendee)));
        }
Exemple #16
0
        public async Task <IActionResult> RemoveMembersInBadge([FromRoute] int badgeId, [FromRoute] int memberId)
        {
            var badge = await _context.BadgeMembers.FirstOrDefaultAsync(x => x.BadgeId == badgeId && x.MemberId == memberId);

            if (badge == null)
            {
                return(BadRequest("El miembro que esta intentando asignar ya tiene ese Badge"));
            }

            _context.Remove(badge);
            await _context.SaveChangesAsync();

            return(Ok());
        }
        public async Task <IActionResult> Handle(FollowMemberCommand request, CancellationToken cancellationToken)
        {
            var me = await _context.Members.FirstOrDefaultAsync(x => x.Id == _currentUser.User.Id, cancellationToken : cancellationToken);

            var member = await _context.Members.FirstOrDefaultAsync(x => x.Id == request.MemberId, cancellationToken : cancellationToken);

            if (member == null)
            {
                return(HttpResponseCodeHelper.NotFound());
            }
            me.Follow(member);
            await _context.SaveChangesAsync(cancellationToken);

            return(HttpResponseCodeHelper.NotContent());
        }
Exemple #18
0
        public async Task <IActionResult> Handle(UpdateInformationCommand request, CancellationToken cancellationToken)
        {
            var member = await _context.Members.Include(x => x.PushNotifications).FirstOrDefaultAsync(x => x.Id == _currentUser.User.Id);

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


            member.AddPushNotification(request.PushNotificationId);
            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.NotContent());
        }
        public async Task <IActionResult> Handle(AddMaterialCommand 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"));
            }
            @event.AddMaterial(request.Title, request.Link);

            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.NotContent());
        }
Exemple #20
0
        public async Task <IActionResult> Handle(DeleteGroupCodeCommand request, CancellationToken cancellationToken)
        {
            var groupCode = await _context.GroupCodes.Include(x => x.Members)
                            .FirstOrDefaultAsync(x => x.Id == request.GroupCodeId);

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

            _context.GroupCodes.Remove(groupCode);
            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.NotContent());
        }
        public async Task <IActionResult> Handle(CreateGroupCodeCommand request, CancellationToken cancellationToken)
        {
            var eventToUpdate = await _context.Events.FirstOrDefaultAsync(x => x.Id == request.EventId);

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

            var groupCode = eventToUpdate.CreateGroupCode(request.Detail);

            await _context.SaveChangesAsync(cancellationToken);

            return(HttpResponseCodeHelper.Ok(_mapper.Map <CreateGroupCodeCommand.Response>(groupCode)));
        }
Exemple #22
0
        public async Task <IActionResult> Handle(AssignBadgeToBadgeGroupCommand request, CancellationToken cancellationToken)
        {
            var badge = await _context.Badges.FirstOrDefaultAsync(x => x.Id == request.BadgeId);

            var badgeGroup = await _context.BadgeGroups.FirstOrDefaultAsync(x => x.Id == request.BadgeGroupId);

            if (badge == null || badgeGroup == null)
            {
                return(new StatusCodeResult(404));
            }

            badgeGroup.Badges.Add(badge);
            await _context.SaveChangesAsync();

            return(new StatusCodeResult(204));
        }
Exemple #23
0
        public async Task <IActionResult> Handle(UpdateGroupCodeCommand request, CancellationToken cancellationToken)
        {
            var groupCode = await _context.GroupCodes.FirstOrDefaultAsync(x => x.Id == request.GroupCodeId);

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

            _mapper.Map(request, groupCode);
            _context.Entry(groupCode).State = EntityState.Modified;

            await _context.SaveChangesAsync();


            return(HttpResponseCodeHelper.NotContent());
        }
        public async Task ProcessAttendees(Event eventToSync)
        {
            if (eventToSync.Platform != EventPlatform.EventBrite)
            {
                return;
            }
            var meetupAttendees = await _eventBriteServices.GetAttendees(eventToSync.EventId);

            foreach (var attendees in meetupAttendees)
            {
                var attendace = eventToSync.Attendees.FirstOrDefault(x => x.Member.Email == attendees.Profile.Email);
                if (attendace == null)
                {
                    var member = await _context.Members.FirstOrDefaultAsync(x => x.Email.ToUpper() == attendees.Profile.Email.ToUpper());

                    if (member == null)
                    {
                        member = new Member
                        {
                            FirstName = attendees.Profile.FirstName,
                            LastName  = attendees.Profile.LastName,
                            Email     = attendees.Profile.Email,
                        }
                    }
                    ;
                    if ((attendees.CheckIn))
                    {
                        attendace = new Attendance(member, eventToSync, true, AttendanceRegisterType.ExternalPage);
                    }
                    else
                    {
                        attendace = new Attendance(member, eventToSync, false, AttendanceRegisterType.ExternalPage);
                    }
                    await _context.Attendances.AddAsync(attendace);
                }
                else
                {
                    if ((attendees.CheckIn))
                    {
                        attendace.Attend();
                    }
                }
            }
            await _context.SaveChangesAsync();
        }
    }
        public async Task <IActionResult> Handle(UnFollowMemberCommand request, CancellationToken cancellationToken)
        {
            var me = await _context.Members.Include(x => x.FollowingMembers).FirstOrDefaultAsync(x => x.Id == _currentUser.User.Id);

            var following = await _context.FollowingMembers.Include(x => x.Member)
                            .Include(x => x.Following)
                            .FirstOrDefaultAsync(x => x.Member.Id == _currentUser.User.Id
                                                 &&
                                                 x.Following.Id == request.MemberId);

            if (following == null)
            {
                return(HttpResponseCodeHelper.NotFound());
            }
            me.UnFollow(following);
            await _context.SaveChangesAsync();

            return(HttpResponseCodeHelper.NotContent());
        }
Exemple #26
0
        public async Task <IActionResult> Handle(UpdateEventCommand request, CancellationToken cancellationToken)
        {
            var eventToUpdate = await _context.Events.Include(x => x.Sponsors).FirstOrDefaultAsync(x => x.Id == request.Id);

            if (eventToUpdate == null)
            {
                return(new StatusCodeResult(402));
            }



            _mapper.Map(request, eventToUpdate);

            if (request?.Live == true && !eventToUpdate.Live)
            {
                eventToUpdate.SetLive();
            }
            else if (request?.Live == false)
            {
                eventToUpdate.SetUnLive();
            }
            if (request?.GeneralAttended == true && !eventToUpdate.GeneralAttended)
            {
                eventToUpdate.EnableGeneralAttendace();
            }
            else if (request?.GeneralAttended == false)
            {
                eventToUpdate.DisableGeneralAttendace();
            }



            _context.Entry(eventToUpdate).State = EntityState.Modified;

            await _context.SaveChangesAsync();


            return(new ObjectResult(_mapper.Map(eventToUpdate, new EventDetail()))
            {
                StatusCode = 200
            });
        }
        public async Task Process()
        {
            var eventsToAdd = await _meetupServices.GetAllEvents();

            var mines = _context.Events.Where(x => x.Platform == EventPlatform.Meetup).ToList();
            var eventMeetupProcesseds = new List <Event>();

            foreach (var eventToAdd in eventsToAdd)
            {
                var eventToCheck = mines.FirstOrDefault(x => x.EventId == eventToAdd.Id.ToString());
                if (eventToCheck == null)
                {
                    eventMeetupProcesseds.Add(new Event
                    {
                        Description = eventToAdd.Description,
                        Title       = eventToAdd.Name,
                        Url         = eventToAdd.Link.AbsoluteUri,
                        EventId     = eventToAdd.Id.ToString(),
                        Date        = eventToAdd.LocalDate.Date,
                        ImageUrl    = eventToAdd?.FeaturedPhoto?.HighresLink?.AbsoluteUri,
                        Platform    = EventPlatform.Meetup
                    });
                    _logger.LogInformation($"Created new event from Meetup : {eventToAdd.Id.ToString()}");
                }
                else if (!eventToCheck.Done)
                {
                    eventMeetupProcesseds.Add(eventToCheck);
                }
            }

            if (eventMeetupProcesseds.Any())
            {
                _context.Events.AddRange(eventMeetupProcesseds.Where(x => x.Id == 0));
            }
            await _context.SaveChangesAsync();

            foreach (var eventMeetupProcessed in eventMeetupProcesseds)
            {
                await _syncServices.SyncEvent(eventMeetupProcessed.Id);
            }
        }
        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(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))));
        }
        public async Task <IActionResult> Handle(DeleteBadgeCommand request, CancellationToken cancellationToken)
        {
            var badge = await _context.Badges.FirstOrDefaultAsync(x => x.Id == request.Id);

            if (badge == null)
            {
                return(new StatusCodeResult(404));
            }
            if (!(await _context.Badges.AnyAsync(x => x.Id == request.Id && !x.Members.Any())))
            {
                return(new StatusCodeResult(409));
            }

            if (await badgesServices.RemoveAsync(badge.ImageName))
            {
                _context.Remove(badge);
                await _context.SaveChangesAsync();
            }
            return(new ObjectResult(request)
            {
                StatusCode = 200
            });
        }