Beispiel #1
0
        public (bool ValidationResult, string ValidationMessage) ValidateSearchForEvent(EventSearchFilter eventSearchFilter)
        {
            if (eventSearchFilter.MinAge.HasValue && eventSearchFilter.MaxAge.HasValue && eventSearchFilter.MinAge > eventSearchFilter.MaxAge)
            {
                return(false, ErrorDictionary.GetErrorMessage(15, _culture));
            }
            if (eventSearchFilter.Status.HasValue && !Enum.IsDefined(typeof(EventStatus), eventSearchFilter.Status))
            {
                return(false, ErrorDictionary.GetErrorMessage(13, _culture));
            }
            if (eventSearchFilter.Type.HasValue && !Enum.IsDefined(typeof(EventType), eventSearchFilter.Type))
            {
                return(false, ErrorDictionary.GetErrorMessage(14, _culture));
            }
            var cities = _cityLogic.GetCities().Result;

            if (eventSearchFilter.CityId.HasValue)
            {
                if (!cities.Any(x => x.CityId == eventSearchFilter.CityId))
                {
                    return(false, ErrorDictionary.GetErrorMessage(30, _culture));
                }
            }
            return(true, string.Empty);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public (bool ValidationResult, string ValidationMessage) ValidateAddPromoRewardRequest(PromoRewardRequestModel request)
        {
            if (request.Images == null || request.Images.Count < 1 || request.Images.Count > 2)
            {
                return(false, ErrorDictionary.GetErrorMessage(47, _culture));
            }
            if (string.IsNullOrWhiteSpace(request.AccountingNumber))
            {
                return(false, ErrorDictionary.GetErrorMessage(48, _culture));
            }
            var eventEntity = _eventRepository.GetEvent(request.EventUid).Result;

            if (eventEntity == null)
            {
                return(false, ErrorDictionary.GetErrorMessage(10, _culture));
            }
            if (eventEntity.EventStatusId != (long)EventStatus.Ended)
            {
                return(false, ErrorDictionary.GetErrorMessage(49, _culture));
            }
            if (eventEntity.PromoRewardRequests.Any())
            {
                return(false, ErrorDictionary.GetErrorMessage(54, _culture));
            }
            return(true, string.Empty);
        }
Beispiel #4
0
 public (bool ValidationResult, string ValidationMessage) ValidateGetRandomPerson(RandomPersonFilter randomPersonFilter)
 {
     if (randomPersonFilter.MinAge.HasValue && (randomPersonFilter.MinAge < 0 || randomPersonFilter.MinAge > 150))
     {
         return(false, ErrorDictionary.GetErrorMessage(22, _culture));
     }
     if (randomPersonFilter.MaxAge.HasValue && (randomPersonFilter.MaxAge < 0 || randomPersonFilter.MaxAge > 150))
     {
         return(false, ErrorDictionary.GetErrorMessage(22, _culture));
     }
     if (randomPersonFilter.MinAge.HasValue && randomPersonFilter.MaxAge.HasValue && randomPersonFilter.MinAge > randomPersonFilter.MaxAge)
     {
         return(false, ErrorDictionary.GetErrorMessage(15, _culture));
     }
     if (!_eventRepository.CheckEventExistence(randomPersonFilter.EventUid).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(10, _culture));
     }
     if (randomPersonFilter.CityId.HasValue)
     {
         var cities = _cityLogic.GetCities().Result;
         if (!cities.Any(x => x.CityId == randomPersonFilter.CityId.Value))
         {
             return(false, ErrorDictionary.GetErrorMessage(30, _culture));
         }
     }
     return(true, string.Empty);
 }
Beispiel #5
0
 public (bool ValidationResult, string ValidationMessage) ValidateUpdatePerson(UpdatePersonModel model, Guid personUid)
 {
     if (model.Name != null && string.IsNullOrWhiteSpace(model.Name))
     {
         return(false, ErrorDictionary.GetErrorMessage(51, _culture));
     }
     if (!_personRepository.CheckPersonExistence(personUid).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(2, _culture));
     }
     if (!string.IsNullOrEmpty(model.Login) && _personRepository.CheckPersonExistence(personUid, model.Login).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(33, _culture));
     }
     if (model.Age.HasValue && model.Age.Value < 14)
     {
         return(false, ErrorDictionary.GetErrorMessage(43, _culture));
     }
     if (model.CityId.HasValue)
     {
         var cities = _cityLogic.GetCities().Result;
         if (!cities.Any(x => x.CityId == model.CityId.Value))
         {
             return(false, ErrorDictionary.GetErrorMessage(30, _culture));
         }
     }
     if (model.Image == null ^ model.MiniImage == null)
     {
         return(false, ErrorDictionary.GetErrorMessage(52, _culture));
     }
     return(true, string.Empty);
 }
Beispiel #6
0
 public (bool ValidationResult, string ValidationMessage) ValidateGetRandomEvent(RandomEventFilter filter)
 {
     if (filter.PersonXCoordinate < 0)
     {
         return(false, ErrorDictionary.GetErrorMessage(23, _culture));
     }
     if (filter.PersonYCoordinate < 0)
     {
         return(false, ErrorDictionary.GetErrorMessage(23, _culture));
     }
     if (filter.CityId.HasValue)
     {
         var cities = _cityLogic.GetCities().Result;
         if (!cities.Any(x => x.CityId == filter.CityId))
         {
             return(false, ErrorDictionary.GetErrorMessage(30, _culture));
         }
     }
     if (filter.EventTypes != null && filter.EventTypes.Any())
     {
         foreach (var type in filter.EventTypes)
         {
             if (!Enum.IsDefined(typeof(EventType), type))
             {
                 return(false, ErrorDictionary.GetErrorMessage(14, _culture));
             }
         }
     }
     return(true, string.Empty);
 }
Beispiel #7
0
        public (bool ValidationResult, string ValidationMessage) ValidateGetMiniatureImage(Guid imageUid)
        {
            var imageEntity = _personRepository.GetPersonImage(imageUid).Result;

            if (imageEntity == null)
            {
                return(false, ErrorDictionary.GetErrorMessage(12, _culture));
            }
            else
            {
                if (imageEntity.PersonMiniatureImageContentUid.HasValue)
                {
                    if (!_imageRepository.CheckImageExistance(imageEntity.PersonMiniatureImageContentUid.ToString()).Result)
                    {
                        return(false, ErrorDictionary.GetErrorMessage(12, _culture));
                    }
                }
                else
                {
                    if (!_imageRepository.CheckImageExistance(imageUid.ToString()).Result)
                    {
                        return(false, ErrorDictionary.GetErrorMessage(12, _culture));
                    }
                }
            }
            return(true, string.Empty);
        }
        public Task Invoke(HttpContext httpContext)
        {
            StringValues personUid, accessToken;

            if (httpContext.Request.Headers.TryGetValue(AuthorizationHeaders.PersonUid, out personUid) &&
                httpContext.Request.Headers.TryGetValue(AuthorizationHeaders.AccessToken, out accessToken))
            {
                if (!_authorizationLogic.CheckAccessKey(new Guid(personUid.FirstOrDefault()), accessToken.FirstOrDefault()).Result)
                {
                    httpContext.Response.StatusCode  = (int)HttpStatusCode.Forbidden;
                    httpContext.Response.ContentType = "application/json";
                    return(httpContext.Response.WriteAsync(ErrorDictionary.GetErrorMessage(5, CultureParser.GetCultureFromHttpContext(httpContext))));
                }
                if (_authorizationLogic.CheckThatPersonIsBlocked(new Guid(personUid.FirstOrDefault())).Result)
                {
                    httpContext.Response.StatusCode  = (int)HttpStatusCode.MethodNotAllowed;
                    httpContext.Response.ContentType = "application/json";
                    return(httpContext.Response.WriteAsync(ErrorDictionary.GetErrorMessage(44, CultureParser.GetCultureFromHttpContext(httpContext))));
                }
            }
            else
            {
                httpContext.Response.StatusCode  = (int)HttpStatusCode.Unauthorized;
                httpContext.Response.ContentType = "application/json";
                return(httpContext.Response.WriteAsync(ErrorDictionary.GetErrorMessage(5, CultureParser.GetCultureFromHttpContext(httpContext))));
            }
            return(_next(httpContext));
        }
Beispiel #9
0
 public (bool ValidationResult, string ValidationMessage) ValidateGetPerson(Guid personUid)
 {
     if (!_personRepository.CheckPersonExistence(personUid).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(2, _culture));
     }
     return(true, string.Empty);
 }
Beispiel #10
0
 public (bool ValidationResult, string ValidationMessage) ValidateAddReport(EventReportModel model)
 {
     if (!_eventRepository.CheckEventExistence(model.EventUid).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(10, _culture));
     }
     return(true, string.Empty);
 }
Beispiel #11
0
 public (bool ValidationResult, string ValidationMessage) ValidateAddReport(PersonReportModel model)
 {
     if (!_personRepository.CheckPersonExistence(model.PersonUid).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(2, _culture));
     }
     return(true, string.Empty);
 }
Beispiel #12
0
 public (bool ValidationResult, string ValidationMessage) ValidateGetImage(Guid uid)
 {
     if (!_imageRepository.CheckImageExistance(uid.ToString()).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(12, _culture));
     }
     return(true, string.Empty);
 }
Beispiel #13
0
 public (bool ValidationResult, string ValidationMessage) ValidateAddEvent(AddEventModel model)
 {
     if (string.IsNullOrWhiteSpace(model.Name))
     {
         return(false, ErrorDictionary.GetErrorMessage(16, _culture));
     }
     if (!Enum.IsDefined(typeof(EventStatus), model.Status))
     {
         return(false, ErrorDictionary.GetErrorMessage(13, _culture));
     }
     if (model.Types == null || !model.Types.Any())
     {
         return(false, ErrorDictionary.GetErrorMessage(36, _culture));
     }
     else
     {
         if (model.Types.Count != model.Types.Distinct().Count())
         {
             return(false, ErrorDictionary.GetErrorMessage(37, _culture));
         }
         if (model.Types.Count > 3)
         {
             return(false, ErrorDictionary.GetErrorMessage(35, _culture));
         }
         foreach (var type in model.Types)
         {
             if (!Enum.IsDefined(typeof(EventType), type))
             {
                 return(false, ErrorDictionary.GetErrorMessage(14, _culture));
             }
         }
     }
     if (model.StartTime > model.EndTime)
     {
         return(false, ErrorDictionary.GetErrorMessage(42, _culture));
     }
     if (model.MinAge.HasValue && model.MaxAge.HasValue && model.MinAge > model.MaxAge)
     {
         return(false, ErrorDictionary.GetErrorMessage(15, _culture));
     }
     if (model.IsOnline.HasValue && !model.IsOnline.Value && !model.CityId.HasValue)
     {
         return(false, ErrorDictionary.GetErrorMessage(31, _culture));
     }
     if (model.IsOnline.HasValue && model.IsOnline.Value && model.CityId.HasValue)
     {
         return(false, ErrorDictionary.GetErrorMessage(32, _culture));
     }
     if (model.CityId.HasValue)
     {
         var cities = _cityLogic.GetCities().Result;
         if (!cities.Any(x => x.CityId == model.CityId))
         {
             return(false, ErrorDictionary.GetErrorMessage(30, _culture));
         }
     }
     return(true, string.Empty);
 }
Beispiel #14
0
        public (bool ValidationResult, string ValidationMessage) ValidateAddChatMessage(AddMessageModel request, Guid personUid)
        {
            var personChatList = _chatLogic.GetPersonChatList(personUid).Result;

            if (!personChatList.Any(x => x.ChatUid == request.ChatUid))
            {
                return(false, ErrorDictionary.GetErrorMessage(20, _culture));
            }
            return(true, string.Empty);
        }
Beispiel #15
0
 public (bool ValidationResult, string ValidationMessage) ValidateAddChat(List <Guid> chatParticipants)
 {
     foreach (var personUid in chatParticipants)
     {
         if (!_personRepository.CheckPersonExistence(personUid).Result)
         {
             return(false, ErrorDictionary.GetErrorMessage(2, _culture));
         }
     }
     return(true, string.Empty);
 }
Beispiel #16
0
 public (bool ValidationResult, string ValidationMessage) ValidateUpdateEvent(UpdateEventModel model)
 {
     if (!_eventRepository.CheckEventExistence(model.EventUid).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(10, _culture));
     }
     if (model.Status.HasValue && !Enum.IsDefined(typeof(EventStatus), model.Status))
     {
         return(false, ErrorDictionary.GetErrorMessage(13, _culture));
     }
     if (model.Types != null)
     {
         if (model.Types.Count != model.Types.Distinct().Count())
         {
             return(false, ErrorDictionary.GetErrorMessage(37, _culture));
         }
         if (model.Types.Count > 3)
         {
             return(false, ErrorDictionary.GetErrorMessage(35, _culture));
         }
         foreach (var type in model.Types)
         {
             if (!Enum.IsDefined(typeof(EventType), type))
             {
                 return(false, ErrorDictionary.GetErrorMessage(14, _culture));
             }
         }
     }
     if (model.MinAge.HasValue && model.MaxAge.HasValue && model.MinAge > model.MaxAge)
     {
         return(false, ErrorDictionary.GetErrorMessage(15, _culture));
     }
     if (model.StartTime.HasValue && model.EndTime.HasValue && model.StartTime > model.EndTime)
     {
         return(false, ErrorDictionary.GetErrorMessage(42, _culture));
     }
     if (model.CityId.HasValue)
     {
         var cities = _cityLogic.GetCities().Result;
         if (!cities.Any(x => x.CityId == model.CityId))
         {
             return(false, ErrorDictionary.GetErrorMessage(30, _culture));
         }
     }
     if (model.PrimaryImage != null && model.PrimaryImage.Any())
     {
         var eventModel = _eventRepository.GetEvent(model.EventUid).Result;
         if (eventModel.EventImageContentEntities.Any(x => x.IsPrimary.HasValue && x.IsPrimary.Value))
         {
             return(false, ErrorDictionary.GetErrorMessage(46, _culture));
         }
     }
     return(true, string.Empty);
 }
Beispiel #17
0
 public (bool ValidationResult, string ValidationMessage) ValidateGetNewChatMessages(Guid chatUid, Guid?messageUid)
 {
     if (!_chatRepository.CheckChatExistence(chatUid).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(19, _culture));
     }
     if (messageUid.HasValue && !_chatRepository.CheckChatMessageExistence(messageUid.Value).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(11, _culture));
     }
     return(true, string.Empty);
 }
Beispiel #18
0
 public (bool ValidationResult, string ValidationMessage) ValidateRejectRandomPerson(Guid eventUid, Guid personUid)
 {
     if (!_personRepository.CheckPersonExistence(personUid).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(2, _culture));
     }
     if (!_eventRepository.CheckEventExistence(eventUid).Result)
     {
         return(false, ErrorDictionary.GetErrorMessage(10, _culture));
     }
     return(true, string.Empty);
 }
Beispiel #19
0
 public (bool ValidationResult, string ValidationMessage) ValidateFeedback(FeedbackModel model)
 {
     if (string.IsNullOrWhiteSpace(model.Text))
     {
         return(false, ErrorDictionary.GetErrorMessage(39, _culture));
     }
     if (model.Images != null && model.Images.Count > 10)
     {
         return(false, ErrorDictionary.GetErrorMessage(40, _culture));
     }
     return(true, string.Empty);
 }
Beispiel #20
0
        public (bool ValidationResult, string ValidationMessage) ValidateMuteChat(Guid chatUid, Guid personUid)
        {
            if (!_chatRepository.CheckChatExistence(chatUid).Result)
            {
                return(false, ErrorDictionary.GetErrorMessage(19, _culture));
            }
            var personChatList = _chatLogic.GetPersonChatList(personUid).Result;

            if (!personChatList.Any(x => x.ChatUid == chatUid))
            {
                return(false, ErrorDictionary.GetErrorMessage(20, _culture));
            }
            return(true, string.Empty);
        }
Beispiel #21
0
        public (bool ValidationResult, string ValidationMessage) ValidateFriendship(Guid personUid, Guid friendUid)
        {
            var isFriendExists = _personRepository.GetPerson(friendUid).Result != null;

            if (!_personRepository.CheckPersonFriendExistence(personUid, friendUid).Result)
            {
                return(false, ErrorDictionary.GetErrorMessage(17, _culture));
            }
            if (!isFriendExists)
            {
                return(false, ErrorDictionary.GetErrorMessage(2, _culture));
            }

            return(true, string.Empty);
        }
Beispiel #22
0
        public (bool ValidationResult, string ValidationMessage) ValidateGetAccessToken(AuthorizationPersonModel person, string refreshToken)
        {
            if (string.IsNullOrWhiteSpace(refreshToken))
            {
                return(false, ErrorDictionary.GetErrorMessage(8, _culture));
            }
            if (person == null)
            {
                return(false, ErrorDictionary.GetErrorMessage(2, _culture));
            }
            if (person.RefreshToken != refreshToken)
            {
                return(false, ErrorDictionary.GetErrorMessage(4, _culture));
            }

            return(true, string.Empty);
        }
Beispiel #23
0
        public async Task <ActionResult <PersonModel> > GetRandomPerson(RandomPersonFilter randomPersonFilter)
        {
            var uid = new Guid(HttpContext.Request.Headers[AuthorizationHeaders.PersonUid].First());
            var validationResult = _personValidation.ValidateGetRandomPerson(randomPersonFilter);

            if (!validationResult.ValidationResult)
            {
                return(BadRequest(validationResult.ValidationMessage));
            }
            var randomEvent = await _personLogic.GetRandomPerson(randomPersonFilter, uid);

            if (randomEvent == null)
            {
                return(BadRequest(ErrorDictionary.GetErrorMessage(27, CultureParser.GetCultureFromHttpContext(HttpContext))));
            }
            return(randomEvent);
        }
Beispiel #24
0
        public (bool ValidationResult, string ValidationMessage) ValidateRemoveEventImage(Guid personUid, RemoveEventImageModel request)
        {
            var eventEntity = _eventRepository.GetEvent(request.EventUid).Result;

            if (eventEntity == null)
            {
                return(false, ErrorDictionary.GetErrorMessage(10, _culture));
            }
            if (eventEntity.Administrator.PersonUid != personUid)
            {
                return(false, ErrorDictionary.GetErrorMessage(55, _culture));
            }
            if (!eventEntity.EventImageContentEntities.Any(x => x.EventImageContentUid == request.ImageUid))
            {
                return(false, ErrorDictionary.GetErrorMessage(56, _culture));
            }
            return(true, string.Empty);
        }
Beispiel #25
0
 public (bool ValidationResult, string ValidationMessage) ValidateGetPersonListByPage(GetPersonListFilter request)
 {
     if (request.PageNumber < 1)
     {
         return(false, ErrorDictionary.GetErrorMessage(28, _culture));
     }
     if (request.PageSize < 1)
     {
         return(false, ErrorDictionary.GetErrorMessage(29, _culture));
     }
     if (request.CityId.HasValue)
     {
         var cities = _cityLogic.GetCities().Result;
         if (!cities.Any(x => x.CityId == request.CityId.Value))
         {
             return(false, ErrorDictionary.GetErrorMessage(30, _culture));
         }
     }
     return(true, string.Empty);
 }
Beispiel #26
0
        public (bool ValidationResult, string ValidationMessage) ValidateGetCode(string phoneNumber)
        {
            if (string.IsNullOrWhiteSpace(phoneNumber))
            {
                return(false, ErrorDictionary.GetErrorMessage(6, _culture));
            }
            else if (!Regex.Match(phoneNumber, RegexTemplates.PhoneTemplate).Success)
            {
                return(false, ErrorDictionary.GetErrorMessage(6, _culture));
            }
            var person = _authorizationRepository.GetPerson(phoneNumber).Result;

            if (person != null && person.TemporaryCodeTime.HasValue)
            {
                var timeDifference = (DateTime.UtcNow - person.TemporaryCodeTime.Value).TotalSeconds;
                if (timeDifference < 30)
                {
                    return(false, ErrorDictionary.GetErrorMessage(45, _culture));
                }
            }
            return(true, string.Empty);
        }
Beispiel #27
0
        public (bool ValidationResult, string ValidationMessage) ValidateSetCode(AuthorizationPersonModel person, string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return(false, ErrorDictionary.GetErrorMessage(7, _culture));
            }
            else if (!Regex.Match(code, RegexTemplates.AuthorizationCodeTemplate).Success)
            {
                return(false, ErrorDictionary.GetErrorMessage(7, _culture));
            }

            if (person == null)
            {
                return(false, ErrorDictionary.GetErrorMessage(2, _culture));
            }
            else if (person.Code != code)
            {
                return(false, ErrorDictionary.GetErrorMessage(3, _culture));
            }

            return(true, string.Empty);
        }
Beispiel #28
0
        public (bool ValidationResult, string ValidationMessage) ValidateGetPushCode(string phoneNumber, string token)
        {
            if (string.IsNullOrWhiteSpace(phoneNumber))
            {
                return(false, ErrorDictionary.GetErrorMessage(6, _culture));
            }
            else if (!Regex.Match(phoneNumber, RegexTemplates.PhoneTemplate).Success)
            {
                return(false, ErrorDictionary.GetErrorMessage(6, _culture));
            }
            if (string.IsNullOrWhiteSpace(token))
            {
                return(false, ErrorDictionary.GetErrorMessage(38, _culture));
            }
            var authPerson = _authorizationRepository.GetPerson(phoneNumber).Result;
            var corePerson = _personRepository.GetPersonByToken(token).Result;

            if (authPerson == null || corePerson == null || authPerson.PersonUid != corePerson.PersonUid)
            {
                return(false, ErrorDictionary.GetErrorMessage(41, _culture));
            }
            return(true, string.Empty);
        }
Beispiel #29
0
        public (bool ValidationResult, string ValidationMessage) ValidateRemoveEventParticipant(Guid personUid, Guid eventUid, Guid currentPersonUid)
        {
            var eventEntity = _eventRepository.GetPureEvent(eventUid).Result;

            if (!_personRepository.CheckPersonExistence(personUid).Result)
            {
                return(false, ErrorDictionary.GetErrorMessage(2, _culture));
            }
            if (eventEntity == null)
            {
                return(false, ErrorDictionary.GetErrorMessage(10, _culture));
            }
            var participantEntity = _eventRepository.GetParticipant(personUid, eventUid).Result;

            if (participantEntity == null)
            {
                return(false, ErrorDictionary.GetErrorMessage(59, _culture));
            }
            if (eventEntity.Administrator.PersonUid == currentPersonUid)
            {
                return(false, ErrorDictionary.GetErrorMessage(58, _culture));
            }
            return(true, string.Empty);
        }