Exemplo n.º 1
0
        public IActionResult CreateApplicationUserProfile(
            [FromBody] Model.ApplicationUserProfileForCreation applicationUserProfileForCreation)
        {
            // currently the ApplicationUserProfileForCreation object doesn't have any properties,
            // as only the subscriptionlevel can be set and that's set to FreeUser for all
            // new users.  ApplicationUserProfileForCreation is accepted as an example
            // for when you would create a client-level screen where the user must input
            // field values before the profile can be created.

            var subject = User.Claims.FirstOrDefault(c => c.Type == "sub").Value;

            if (_galleryRepository.ApplicationUserProfileExists(subject))
            {
                return(BadRequest());
            }

            var applicationUserProfileEntity =
                _mapper.Map <Entities.ApplicationUserProfile>(applicationUserProfileForCreation);

            // subject must come from the token
            applicationUserProfileEntity.Subject = subject;

            // subscriptionlevel = FreeUser
            applicationUserProfileEntity.SubscriptionLevel = "FreeUser";

            _galleryRepository.AddApplicationUserProfile(applicationUserProfileEntity);

            _galleryRepository.Save();

            var applicationUserProfileToReturn = _mapper.Map <Model.Image>(applicationUserProfileEntity);

            return(CreatedAtRoute("GetApplicationUserProfile",
                                  new {
                id = applicationUserProfileToReturn.Id
            },
                                  applicationUserProfileToReturn));
        }