Example #1
0
        public Result <int> CreateProfile(CreateProfileCommand command)
        {
            if (profileRepository.ProfileExistsForOrganizationUser(command.OrganizationUserId, command.OrganizationId))
            {
                return(new Result <int>(ProfileServiceErrors.ProfileForOrganizationUserAlreadyExists()));
            }

            // TODO -  think about the wanted strategy for empty/optional profile values

            /*if (ValidateProfileValue(command.ProfileValues))
             * {
             *  return new Result<int>(ProfileServiceErrors.InvalidProfileValuesData());
             * }*/

            if (!organizationUserRepository.OrganizationUserExists(command.OrganizationUserId, command.OrganizationId))
            {
                return(new Result <int>(ProfileServiceErrors.InvalidOrganizationUserId()));
            }

            var(invalidProfileParametersFound, invalidProfileParametersCollection) = ValidateProfileParameters(command.ProfileValues.ToList <IProfileValueModel>());

            if (invalidProfileParametersFound)
            {
                return(new Result <int>(invalidProfileParametersCollection));
            }

            var profileId = profileRepository.CreateProfile(command);

            return(new Result <int>(profileId));
        }
Example #2
0
        public EmptyResult UpdateProfile(UpdateProfileCommand command)
        {
            if (!profileRepository.ProfileExistsForOrganizationUser(command.OrganizationUserId, command.OrganizationId))
            {
                return(new Result <int>(ProfileServiceErrors.InvalidOrganizationUserId()));
            }

            var(invalidProfileParametersFound, invalidProfileParametersCollection) = ValidateProfileParameters(command.ProfileValues.ToList <IProfileValueModel>());

            if (invalidProfileParametersFound)
            {
                return(new Result <int>(invalidProfileParametersCollection));
            }

            profileRepository.UpdateProfile(command);
            return(new EmptyResult());
        }
Example #3
0
        public EmptyResult DeleteProfile(DeleteProfileCommand command)
        {
            if (!command.OrganizationUserId.HasValue)
            {
                return(new Result <EmptyResult>(ProfileServiceErrors.InvalidOrganizationUserId()));
            }
            if (!command.OrganizationId.HasValue)
            {
                return(new Result <EmptyResult>(ProfileServiceErrors.InvalidOrganizationId()));
            }

            if (!profileRepository.ProfileExistsForOrganizationUser(command.OrganizationUserId.Value, command.OrganizationId.Value))
            {
                return(new EmptyResult(ProfileServiceErrors.InvalidProfileId()));
            }

            profileRepository.DeleteProfile(command);
            return(new EmptyResult());
        }