コード例 #1
0
        public async Task <ActionResult <GetEventModel> > AddEventParticipant(EventParticipantModel request)
        {
            var uid = new Guid(HttpContext.Request.Headers[AuthorizationHeaders.PersonUid].First());
            var validationResult = _eventValidation.ValidateAddParticipantModel(request);

            if (!validationResult.ValidationResult)
            {
                return(BadRequest(validationResult.ValidationMessage));
            }
            return(await _eventLogic.AddParticipant(request, uid));
        }
コード例 #2
0
        public async Task <ActionResult <GetEventModel> > UpdateEventParticipant(EventParticipantModel request)
        {
            var validationResult = _eventValidation.ValidateUpdateParticipantModel(request);

            if (!validationResult.ValidationResult)
            {
                return(BadRequest(validationResult.ValidationMessage));
            }
            await _eventLogic.UpdateParticipant(request);

            return(await _eventLogic.GetEvent(request.EventUid));
        }
コード例 #3
0
        private async Task <PersonToEventEntity> CreateParticipantEntity(EventParticipantModel eventParticipantModel)
        {
            var personEntity = await _personRepository.GetPerson(eventParticipantModel.PersonUid);

            var eventEntity = await _eventRepository.GetPureEvent(eventParticipantModel.EventUid);

            return(new PersonToEventEntity
            {
                EventId = eventEntity.EventId,
                PersonId = personEntity.PersonId,
                ParticipantStatusId = (long)eventParticipantModel.ParticipantStatus
            });
        }
コード例 #4
0
        public async Task <ActionResult> AcceptRandomPerson(EventParticipantModel request)
        {
            var uid = new Guid(HttpContext.Request.Headers[AuthorizationHeaders.PersonUid].First());
            var validationResult = _eventValidation.ValidateAddParticipantModel(request);

            if (!validationResult.ValidationResult)
            {
                return(BadRequest(validationResult.ValidationMessage));
            }
            await _eventLogic.AddParticipant(request, uid);

            await _eventLogic.AddEventSwipeHistory(request.PersonUid, request.EventUid);

            return(Ok(Messages.GetMessageJson(MessageTitles.RandomPersonAccepted, CultureParser.GetCultureFromHttpContext(HttpContext))));
        }
コード例 #5
0
        public async Task <GetEventModel> AddParticipant(EventParticipantModel eventParticipantModel, Guid personUid)
        {
            var entity = await CreateParticipantEntity(eventParticipantModel);

            await _eventRepository.AddParticipant(entity);

            var person = await _personRepository.GetPerson(eventParticipantModel.PersonUid);

            var eventEntity = await _eventRepository.GetPureEvent(eventParticipantModel.EventUid);

            if (!string.IsNullOrEmpty(person.Token) && eventParticipantModel.PersonUid != personUid)
            {
                await _pushNotificationService.SendPushNotification(person.Token,
                                                                    MessageTitles.AddParticipantNotificationMessage,
                                                                    new Dictionary <FirebaseNotificationKeys, string> {
                    [FirebaseNotificationKeys.Url] = string.Format(FirebaseNotificationTemplates.EventUrlTemplate, eventEntity.EventUid)
                },
                                                                    "Lume",
                                                                    eventEntity.Name);
            }
            if (eventEntity.Administrator != null && eventEntity.Administrator.Token != null && eventEntity.Administrator.PersonUid != personUid)
            {
                if (eventParticipantModel.ParticipantStatus == ParticipantStatus.WaitingForApproveFromEvent)
                {
                    await _pushNotificationService.SendPushNotification(eventEntity.Administrator.Token,
                                                                        MessageTitles.ParticipantWaitingForApproval,
                                                                        new Dictionary <FirebaseNotificationKeys, string> {
                        [FirebaseNotificationKeys.Url] = string.Format(FirebaseNotificationTemplates.EventUrlTemplate, eventEntity.EventUid)
                    },
                                                                        "Lume",
                                                                        eventEntity.Name);
                }
                else if (eventParticipantModel.ParticipantStatus == ParticipantStatus.Active)
                {
                    await _pushNotificationService.SendPushNotification(eventEntity.Administrator.Token,
                                                                        MessageTitles.ParticipantJoinedTheEvent,
                                                                        new Dictionary <FirebaseNotificationKeys, string> {
                        [FirebaseNotificationKeys.Url] = string.Format(FirebaseNotificationTemplates.EventUrlTemplate, eventEntity.EventUid)
                    },
                                                                        "Lume",
                                                                        eventEntity.Name);
                }
            }
            return(await GetEvent(eventParticipantModel.EventUid));
        }
コード例 #6
0
        public async Task UpdateParticipant(EventParticipantModel eventParticipantModel)
        {
            var entity = await CreateParticipantEntity(eventParticipantModel);

            await _eventRepository.UpdateParticipant(entity);
        }
コード例 #7
0
ファイル: EventValidation.cs プロジェクト: kirill-shevch/Lume
        public (bool ValidationResult, string ValidationMessage) ValidateAddParticipantModel(EventParticipantModel model)
        {
            var eventEntity = _eventRepository.GetEvent(model.EventUid).Result;

            if (eventEntity == null)
            {
                return(false, ErrorDictionary.GetErrorMessage(10, _culture));
            }
            if (eventEntity.EventStatusId == (long)EventStatus.Canceled || eventEntity.EventStatusId == (long)EventStatus.Ended)
            {
                return(false, ErrorDictionary.GetErrorMessage(57, _culture));
            }
            if (!_personRepository.CheckPersonExistence(model.PersonUid).Result)
            {
                return(false, ErrorDictionary.GetErrorMessage(2, _culture));
            }
            var participant = eventEntity.Participants.SingleOrDefault(x => x.Person != null && x.Person.PersonUid == model.PersonUid);

            if (participant != null)
            {
                return(false, ErrorDictionary.GetErrorMessage(24, _culture));
            }
            if (!Enum.IsDefined(typeof(ParticipantStatus), model.ParticipantStatus))
            {
                return(false, ErrorDictionary.GetErrorMessage(21, _culture));
            }
            return(true, string.Empty);
        }