Beispiel #1
0
        private static RegisteredUserDTO GetRegisteredUser(UserDTO user)
        {
            var registerUser = ServiceLocator.RegisteredUserService.FindBy(re => re.UserId == user.Id).FirstOrDefault();

            NullCheck.ThrowArgumentNullEx(registerUser);
            return(registerUser);
        }
Beispiel #2
0
        public override void Update(UserDTO caller, PhoneNumberDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(caller, entity);
            var entityToUpdate = _mapper.DefaultContext.Mapper.Map <PhoneNumber>(entity);

            _repo.Update(entityToUpdate);
        }
Beispiel #3
0
        private static void ValidateType(string type)
        {
            NullCheck.ThrowArgumentNullEx(type);
            if (TypeMinLength > type.Length || type.Length > TypeMaxLength)
            {
                throw new ArgumentException($"{nameof(type)} must have a length between {TypeMinLength} and {TypeMaxLength}.");
            }
            if (TypeStartsWithWhiteSpace())
            {
                throw new ArgumentException($"{nameof(type)} cannot start with a white-space character.");
            }
            if (TypeEndsWithWhiteSpace())
            {
                throw new ArgumentException($"{nameof(type)} cannot end with a white-space character.");
            }
            if (TypeStartsWithDigit())
            {
                throw new ArgumentException($"{nameof(type)} cannot start with a digit.");
            }
            if (TypeContainsIllegalCharacters())
            {
                throw new ArgumentException($"{nameof(type)} can only contain letters, digits and white-space characters.");
            }

            bool TypeStartsWithWhiteSpace() => type[0] == ' ';
            bool TypeEndsWithWhiteSpace() => type[type.Length - 1] == ' ';
            bool TypeStartsWithDigit() => char.IsDigit(type[0]);
            bool TypeContainsIllegalCharacters() => type.Any(typeCharacter =>
                                                             !char.IsLetter(typeCharacter) &&
                                                             !char.IsDigit(typeCharacter) &&
                                                             typeCharacter != ' ');
        }
        public override void Update(UserDTO caller, AddressDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(entity);
            var entityToUpdate = _mapper.DefaultContext.Mapper.Map <Address>(entity);

            _repo.Update(entityToUpdate);
        }
        public override void Delete(UserDTO caller, EmailDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(caller, entity);
            var entityToDelete = _mapper.DefaultContext.Mapper.Map <Email>(entity);

            _repo.Delete(entityToDelete);
        }
        public override void Update(UserDTO caller, EmailDTO entity, Expression <Func <IUpdateConfiguration <Email>, object> > graph)
        {
            NullCheck.ThrowArgumentNullEx(caller, entity);
            var entityToUpdate = _mapper.DefaultContext.Mapper.Map <Email>(entity);

            _repo.Update(entityToUpdate, graph);
        }
Beispiel #7
0
 public void AddRoleRelation(UserDTO caller, UserDTO user, Role role)
 {
     NullCheck.ThrowArgumentNullEx(user);
     _target.CheckPermission(caller);
     user = user.Id == 0 ? DbEntityExistensChecker.TryGetExistingUserFromDb(user) ?? DbEntityAdder.AddUserToDb(user) : user;
     AddRoleRelationToDb(CreateRoleRelation(user, role));
 }
        public override void Add(UserDTO caller, BoatDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(caller, entity);
            var entityToAdd = _mapper.DefaultContext.Mapper.Map <Boat>(entity);

            _repo.Add(entityToAdd);
        }
Beispiel #9
0
 public void AddEmailToClub(UserDTO caller, EmailDTO email)
 {
     NullCheck.ThrowArgumentNullEx(caller, email);
     CheckPermission(caller);
     email = email.Id == 0 ? DbEntityExistensChecker.TryGetExistingEmailFromDb(email) ?? DbEntityAdder.AddEmailToDb(email) : email;
     SaveRelationToDb(CreateRelation(email));
 }
Beispiel #10
0
 public void RemoveUserFromTeam(UserDTO caller, UserDTO userToRemove)
 {
     NullCheck.ThrowArgumentNullEx(caller, userToRemove);
     CheckPermissionAllowSelfHandling(caller, userToRemove);
     ValidateAction(userToRemove);
     RemoveRelationFromDb(GetTeamUserRelation(userToRemove));
 }
Beispiel #11
0
 internal override IRoleJunction GetRoleRelation(UserDTO user, Role role)
 {
     NullCheck.ThrowArgumentNullEx(user, role);
     return(ServiceLocator.ClubsUsersUserRolesJunctionsService
            .FindBy(uCJunc => uCJunc.UserId == user.Id && uCJunc.UserRoleId == (int)role)
            .First());
 }
        public override void Update(UserDTO caller, RegattaDTO entity, Expression <Func <IUpdateConfiguration <Regatta>, object> > graph)
        {
            NullCheck.ThrowArgumentNullEx(caller);
            entity.CheckPermission(caller);
            var entityToUpdate = _mapper.DefaultContext.Mapper.Map <Regatta>(entity);

            _repo.Update(entityToUpdate, graph);
        }
Beispiel #13
0
        public void RemoveUserFromSocialEvent(UserDTO caller, UserDTO userToRemove)
        {
            NullCheck.ThrowArgumentNullEx(caller, userToRemove);
            CheckPermissionAllowSelfHandling(caller, userToRemove);
            ValidateAction(userToRemove);

            RemoveAttendanceRelationFromDb(GetUserSocialEventRelation(userToRemove));
        }
Beispiel #14
0
        public virtual void Update(TEntityDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(entity);

            var entityToUpdate = _mapper.DefaultContext.Mapper.Map <TEntityEF>(entity);

            _repo.Update(entityToUpdate);
        }
Beispiel #15
0
        public virtual void Add(TEntityDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(entity);

            var entityToAdd = _mapper.DefaultContext.Mapper.Map <TEntityEF>(entity);

            _repo.Add(entityToAdd);
        }
        public override void Delete(UserDTO caller, TeamDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(caller, entity);
            entity.CheckPermission(caller);
            var entityToDelete = _mapper.DefaultContext.Mapper.Map <Team>(entity);

            _repo.Delete(entityToDelete);
        }
Beispiel #17
0
 public void AddPhoneNumberToClub(UserDTO caller, PhoneNumberDTO phoneNumber)
 {
     NullCheck.ThrowArgumentNullEx(caller, phoneNumber);
     CheckPermission(caller);
     phoneNumber = phoneNumber.Id == 0 ? DbEntityExistensChecker.TryGetExistingPhoneNumberFromDb(phoneNumber) ??
                   DbEntityAdder.AddPhoneNumberToDb(phoneNumber) : phoneNumber;
     SaveRelationToDb(CreateRelation(phoneNumber));
 }
        public override void Add(UserDTO caller, TeamDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(caller, entity);
            entity.CheckPermissionToAffiliatedEntry(caller);
            var entityToAdd = _mapper.DefaultContext.Mapper.Map <Team>(entity);

            _repo.Add(entityToAdd);
        }
        public override void Add(UserDTO caller, RegattaDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(entity);
            entity.CheckPermissionToAffiliatedClub(caller);
            var entityToAdd = _mapper.DefaultContext.Mapper.Map <Regatta>(entity);

            _repo.Add(entityToAdd);
        }
        public override void Update(UserDTO caller, BoatDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(caller, entity);
            entity.CheckPermission(caller);
            var entityToUpdate = _mapper.DefaultContext.Mapper.Map <Boat>(entity);

            _repo.Update(entityToUpdate);
        }
        public override void Add(UserDTO caller, ClubDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(entity);
            var entityToAdd = _mapper.DefaultContext.Mapper.Map <Club>(entity);

            _repo.Add(entityToAdd);
            MakeCallerAdminForClub(caller, entity);
        }
Beispiel #22
0
 public void AddUserToEntry(UserDTO caller, UserDTO userToAdd)
 {
     NullCheck.ThrowArgumentNullEx(userToAdd);
     CheckPermissionAllowSelfHandling(caller, userToAdd);
     userToAdd = userToAdd.Id == 0 ? DbEntityExistensChecker.TryGetExistingUserFromDb(userToAdd) ??
                 DbEntityAdder.AddUserToDb(userToAdd) : userToAdd;
     AddRelationToDb(GetRelation(userToAdd));
 }
        public override void Add(UserDTO caller, EntryDTO entity)
        {
            NullCheck.ThrowArgumentNullEx(entity);

            MakeCallerResponsiblePersonForEntry(caller, entity);
            var entityToAdd = _mapper.DefaultContext.Mapper.Map <Entry>(entity);

            _repo.Add(entityToAdd);
            AddResponsibleUserToRegisterdUser(entity);
        }
Beispiel #24
0
        public void AddRoleRelation(UserDTO caller, UserDTO user, PhoneNumberDTO phoneNumber, EmailDTO email, Role role)
        {
            NullCheck.ThrowArgumentNullEx(user, phoneNumber, email);
            _target.CheckPermission(caller);
            user        = user.Id == 0 ? DbEntityExistensChecker.TryGetExistingUserFromDb(user) ?? DbEntityAdder.AddUserToDb(user) : user;
            phoneNumber = phoneNumber.Id == 0 ? DbEntityExistensChecker.TryGetExistingPhoneNumberFromDb(phoneNumber) ??
                          DbEntityAdder.AddPhoneNumberToDb(phoneNumber) : phoneNumber;
            email = email.Id == 0 ? DbEntityExistensChecker.TryGetExistingEmailFromDb(email) ?? DbEntityAdder.AddEmailToDb(email) : email;

            AddRoleRelationToDb(CreateRoleRelation(user, phoneNumber, email, role));
        }
Beispiel #25
0
 private void ValidateZipCode(string zipCode)
 {
     NullCheck.ThrowArgumentNullEx(zipCode);
     if (zipCode.Length != ZipCodeLength)
     {
         throw new ArgumentException($"{nameof(zipCode)} must have a length of {ZipCodeLength}.");
     }
     if (zipCode.Any(character => !char.IsDigit(character)))
     {
         throw new ArgumentException($"{nameof(zipCode)} can only contain digits.");
     }
 }
Beispiel #26
0
 public void AddUserToSocialEvent(UserDTO caller, UserDTO userToAdd, int numberOfFriends)
 {
     NullCheck.ThrowArgumentNullEx(caller, userToAdd);
     CheckPermissionAllowSelfHandling(caller, userToAdd);
     if (userToAdd.Permissions.GetAttendancePermissions <SocialEventDTO>().Any(sePer => sePer.Id == Id))
     {
         userToAdd = userToAdd.Id == 0 ? DbEntityExistensChecker.TryGetExistingUserFromDb(userToAdd) ??
                     DbEntityAdder.AddUserToDb(userToAdd) : userToAdd;
         AddRelationToDb(CreateAttendancesRelation(userToAdd, numberOfFriends));
     }
     else
     {
         throw new ArgumentException($"User: {userToAdd.Login} do not have permission to attend this socialevent");
     }
 }
Beispiel #27
0
        public void AddUserToTeam(UserDTO caller, UserDTO userToAdd)
        {
            NullCheck.ThrowArgumentNullEx(caller, userToAdd);
            CheckPermissionAllowSelfHandling(caller, userToAdd);

            if (userToAdd.Permissions.GetTeamParticipationPermissions().Any(t => t.Id == Id))
            {
                userToAdd = userToAdd.Id == 0 ? DbEntityExistensChecker.TryGetExistingUserFromDb(userToAdd) ??
                            DbEntityAdder.AddUserToDb(userToAdd) : userToAdd;
                SaveRelationToDb(CreateRelation(userToAdd));
            }
            else
            {
                throw new ArgumentException($"User: {userToAdd.Login} cannot be added to this team." +
                                            $"Make sure that the user is affiliated with an entry that holds this team");
            }
        }
Beispiel #28
0
        private static void ValidateValue(string value)
        {
            NullCheck.ThrowArgumentNullEx(value);
            if (ValueMinLength > value.Length || value.Length > ValueMaxLength)
            {
                throw new ArgumentException($"{nameof(value)} must have a length between {ValueMinLength} and {ValueMaxLength}.");
            }
            if (ValueDoesNotContainOnlyDigits())
            {
                throw new ArgumentException($"{nameof(value)} can only contain digits.");
            }
            if (ValueDoesNotStartWithZero())
            {
                throw new ArgumentException($"{nameof(value)} must start with zero.");
            }

            bool ValueDoesNotContainOnlyDigits() => value.Any(valueCharacter => !char.IsDigit(valueCharacter));
            bool ValueDoesNotStartWithZero() => value[0] != '0';
        }
Beispiel #29
0
        private void ValidateCountry(string country)
        {
            NullCheck.ThrowArgumentNullEx(country);
            if (country.Any(char.IsDigit))
            {
                throw new ArgumentException($"{nameof(country)} cannot contain digits.");
            }
            if (CountryMinLength > country.Length || country.Length > CountryMaxLength)
            {
                throw new ArgumentException($"{nameof(country)} must have a length between {CountryMinLength} and {CountryMaxLength}.");
            }
            if (CountryStartsWithWhiteSpace())
            {
                throw new ArgumentException($"{nameof(country)} cannot start with a white-space character.");
            }
            if (CountryEndsWithWhiteSpace())
            {
                throw new ArgumentException($"{nameof(country)} cannot end with a white-space character.");
            }
            if (CountryStartsLowerCase())
            {
                throw new ArgumentException($"{nameof(country)} cannot start with a lower case.");
            }
            if (CountryEndsWithUpperCase())
            {
                throw new ArgumentException($"{nameof(country)} cannot end with a upper case.");
            }
            if (CountryContainsIllegalCharacters())
            {
                throw new ArgumentException($"{nameof(country)} can only contain letters and white-space characters.");
            }

            bool CountryStartsWithWhiteSpace() => country[0] == ' ';
            bool CountryEndsWithWhiteSpace() => country[country.Length - 1] == ' ';
            bool CountryStartsLowerCase() => char.IsLower(country[0]);
            bool CountryEndsWithUpperCase() => char.IsUpper(country[country.Length - 1]);
            bool CountryContainsIllegalCharacters() => country.Any(character =>
                                                                   !char.IsLetter(character) &&
                                                                   character != ' ');
        }
Beispiel #30
0
        private void ValidateStreet(string street)
        {
            NullCheck.ThrowArgumentNullEx(street);
            if (StreetMinLength > street.Length || street.Length > StreetMaxLength)
            {
                throw new ArgumentException($"{nameof(street)} must have a length between {StreetMinLength} and {StreetMaxLength}.");
            }
            if (StreetStartsWithWhiteSpace())
            {
                throw new ArgumentException($"{nameof(street)} cannot start with a white-space character.");
            }
            if (StreetEndsWithWhiteSpace())
            {
                throw new ArgumentException($"{nameof(street)} cannot end with a white-space character.");
            }
            if (StreetStartsWithDigit())
            {
                throw new ArgumentException($"{nameof(street)} cannot start with a digit.");
            }
            if (StreetDoesNotContainAnyWhiteSpace())
            {
                throw new ArgumentException($"{nameof(street)} does not contain any white-space characters.");
            }
            if (StreetContainsIllegalCharacters())
            {
                throw new ArgumentException($"{nameof(street)} can only contain letters, digits and white-space characters.");
            }

            bool StreetStartsWithWhiteSpace() => street[0] == ' ';
            bool StreetEndsWithWhiteSpace() => street[street.Length - 1] == ' ';
            bool StreetStartsWithDigit() => char.IsDigit(street[0]);
            bool StreetDoesNotContainAnyWhiteSpace() => street.All(character => character != ' ');
            bool StreetContainsIllegalCharacters() => street.Any(character =>
                                                                 !char.IsLetter(character) &&
                                                                 !char.IsDigit(character) &&
                                                                 character != ' ');
        }