[HttpPost] // Post means create
        public async Task <ActionResult <Profile> > CreateProfile(CreateProfileDto profile)
        {
            var profileDto = await profileRepository.CreateProfile(profile);


            return(CreatedAtAction("GetProfile", new { profileId = profileDto.Id }, profileDto));
        }
예제 #2
0
        public IActionResult CreateProfile([FromBody] CreateProfileDto profile)
        {
            if (!_validateRepository.IsUserNameHandleUnique(profile.User.UserName, profile.Handle))
            {
                return(StatusCode(409, "User allready exists"));
            }

            var prof = AutoMapper.Mapper.Map <Profile>(profile);
            var salt = new byte[128 / 8];

            Random random = new Random();

            random.NextBytes(salt);

            prof.User.PasswordHash = _authorizationManager.GeneratePasswordHash(profile.User.Password, salt);
            prof.User.Salt         = salt;

            _profileRepository.CreateProfile(prof);

            if (!_profileRepository.Save())
            {
                return(StatusCode(500, "There was a problem while handling your request."));
            }

            return(StatusCode(200, "Profile created"));
        }
예제 #3
0
        public Profile CreateProfile(ProfileDTO profileData)
        {
            Profile newProfile = new Profile(profileData);

            _profileRepository.CreateProfile(newProfile);
            return(newProfile);
        }
예제 #4
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));
        }
예제 #5
0
 public IActionResult Create([Bind("Email, Username, FirstName, Last, Street, State, Zip")] Profile profile)
 {
     if (ModelState.IsValid)
     {
         _profileRepo.CreateProfile(profile);
         return(RedirectToAction("Index", "Home"));
     }
     return(View());
 }
예제 #6
0
        public int CreateProfile(string userId)
        {
            var profile = new Data.Contracts.Entities.Profile();

            profileRepository.CreateProfile(profile, userId);
            profileRepository.Save();
            var profileId = profileRepository.GetProfileId(profile);

            return(profileId);
        }
예제 #7
0
        public Task <bool> Handle(CreateProfileCommand request, CancellationToken cancellationToken)
        {
            _profileRepository.CreateProfile(new Profile
            {
                AvatarUrl  = request.AvatarUrl,
                Name       = request.Name,
                Id         = request.Id,
                CreateDate = DateTime.UtcNow.ToLocalTime()
            });

            return(Task.FromResult(true));
        }
        public async Task <IActionResult> Registrarion(Profile request)
        {
            Profile user = new Profile
            {
                Name     = request.Name,
                Login    = request.Login,
                Password = request.Password
            };

            await _Repository.CreateProfile(user);

            return(Ok(200));
        }
        public IActionResult PostProfile([FromBody] ProfilesModel Model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_profileRepository.CreateProfile(Model))
            {
                ModelState.AddModelError("", $"Something went wrong saving the job " +
                                         $"{Model.Id}");
                return(StatusCode(500, ModelState));
            }

            return(Ok(new { userProfileAdded = true }));
        }
예제 #10
0
        public async Task <ActionResult <HospitalProfile> > CreateProfile(HospitalProfileVM newProfileVm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var createdProfile = await _repository.CreateProfile(newProfileVm);

            if (createdProfile == null)
            {
                ModelState.AddErrorMessage("Unable to create profile");
                return(BadRequest(ModelState));
            }

            return(Ok(createdProfile));
        }
예제 #11
0
        public void Register(ProfileAuthenticationRequestDto profileFromUi)
        {
            var invalidParams = new List <string>();

            if (!IsValidEmail(profileFromUi.Email))
            {
                invalidParams.Add(nameof(profileFromUi.Email));
            }

            if (!IsValidPassword(profileFromUi.Password))
            {
                invalidParams.Add(nameof(profileFromUi.Password));
            }

            if (invalidParams.Any())
            {
                throw new ValidationException(invalidParams);
            }


            CreatePasswordHash(profileFromUi.Password, out byte[] passwordHash,
                               out byte[] passwordSalt);

            var profileForDb = new Profile()
            {
                Email        = profileFromUi.Email,
                PasswordHash = passwordHash,
                PasswordSalt = passwordSalt
            };

            try
            {
                _profileRepository.CreateProfile(profileForDb);
            }
            catch (DbUpdateException dbUpdateException)
            {
                if (dbUpdateException.InnerException?.Message
                    .Contains("Email") ?? false)
                {
                    throw new DomainModelException("Email already used");
                }
                throw;
            }
        }
예제 #12
0
        public async Task <ActionResult <ProfileDto> > Register(RegisterData data)
        {
            var user = await userService.Register(data, this.ModelState);

            if (!ModelState.IsValid)
            {
                return(BadRequest(new ValidationProblemDetails(ModelState)));
            }

            CreateProfileDto profile = new CreateProfileDto {
                DisplayName = data.Username
            };

            var profileDto = await profileRepository.CreateProfile(profile, user);

            profileDto = await profileRepository.CreateProfileMember(new CreateProfileMember { ProfileId = profileDto.Id, UserId = user.Id });

            return(Ok(profileDto));
        }
예제 #13
0
        public IActionResult Create([Bind("Email, UserName, FirstName, LastName, Street, State, Zip")] Profile profile)
        {
            var profileList = _profileRepo.ReadAllProfiles();


            if (ModelState.IsValid)
            {
                foreach (var profileItem in profileList)
                {
                    if (profileItem.UserName == profile.UserName)
                    {
                        return(RedirectToAction("Create", "Profile", new { error = true }));
                    }
                }
                _userRepository.ReadUser(User.Identity.Name).Profile = profile;
                _profileRepo.CreateProfile(profile);
                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
예제 #14
0
 public IActionResult Create(Profile profile)
 {
     // Checks if the username is already used for a profile
     // if it is, display error message
     if (_profile.UsernameExists(profile.Username))
     {
         ModelState.AddModelError("Username", "Username is already taken!");
     }
     // if a username is not useed, and the profile is valid
     if (ModelState.IsValid)
     {
         // read the current user's email
         var user = _user.ReadUser(User.Identity.Name);
         profile.User = user;
         //create the profile
         _profile.CreateProfile(profile);
         //redirect to Home/Index
         return(RedirectToAction("Index", "Home"));
     }
     return(View());                                                                                                           //if profile isn't valid, refresh view
 }