Beispiel #1
0
        // POST: api/Profiles
        public async Task <IHttpActionResult> Post()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                return(BadRequest());
            }

            var result = await Request.Content.ReadAsMultipartAsync();

            var requestJson = await result.Contents[0].ReadAsStringAsync();
            var model       = JsonConvert.DeserializeObject <ProfileBindingModel>(requestJson);

            if (result.Contents.Count > 1)
            {
                model.PictureUrl = await CreateBlob(result.Contents[1]);
            }

            var accountId = User.Identity.GetUserId();

            var profile = new Profile()
            {
                AccountId  = accountId,
                FirstName  = model.FirstName,
                LastName   = model.LastName,
                PictureUrl = model.PictureUrl
            };

            var repository = new ProfileRepository();

            repository.Create(profile);

            return(Ok());
        }
Beispiel #2
0
 public bool Create(RegisterAccountModel account)
 {
     if (string.IsNullOrEmpty(account.Username))
     {
         throw new ArgumentNullException(nameof(account.Username));
     }
     if (string.IsNullOrEmpty(account.Password))
     {
         throw new ArgumentNullException(nameof(account.Password));
     }
     if (string.IsNullOrEmpty(account.Pin))
     {
         throw new ArgumentNullException(nameof(account.Pin));
     }
     if (string.IsNullOrEmpty(account.Name))
     {
         throw new ArgumentNullException(nameof(account.Name));
     }
     if (account.Username.Length < 6 || account.Password.Length < 6 || account.Pin.Length < 4 || account.Pin.Length > 6)
     {
         return(false);
     }
     if (profileRepository.GetAccount(account.Username) != null)
     {
         return(false);
     }
     return(profileRepository.Create(account) != 0);
     // acount username already exists return false otherwise else create
 }
Beispiel #3
0
        public async Task <CreateProfileResponse> Create([FromBody] CreateProfileRequest request)
        {
            var profile = await profileRepository.Create(request.Name, request.ProfileTypeId, ApiUser.Id);

            return(new CreateProfileResponse()
            {
                Success = profile != null && profile.Id != 0
            });
        }
Beispiel #4
0
        internal Profile GetOrCreateProfile(Profile userInfo)
        {
            Profile profile = _repo.GetById(userInfo.Id);

            if (profile == null)
            {
                return(_repo.Create(userInfo));
            }
            return(profile);
        }
Beispiel #5
0
        public Profile GetOrCreateProfile(Profile userInfo)
        {
            Profile foundProfile = _repo.GetByEmail(userInfo.Email);

            if (foundProfile == null)
            {
                return(_repo.Create(userInfo));
            }
            return(foundProfile);
        }
Beispiel #6
0
        public async Task <RegisterResponse> PerformRegister([FromBody] RegisterRequest register)
        {
            RegisterResponse response = new RegisterResponse();

            int?profileId = null, userId = null;

            //check for email conflicts in partnercode
            UserLookup user = new UserLookup();

            user.email       = register.user.Email;
            user.partnercode = register.user.Partnercode;
            User userModel = (await userRepository.Lookup(user)).FirstOrDefault();

            //if uniquenick set, check for uniquenick conflictss in namespaceid
            if (register.profile?.Uniquenick != null && userModel != null)
            {
                var checkData = await profileRepository.CheckUniqueNickInUse(register.profile.Uniquenick, register.profile.Namespaceid, register.user.Partnercode);

                if (checkData.Item1)
                {
                    if (userModel.Password.CompareTo(register.password) == 0)
                    {
                        profileId = checkData.Item2;
                        userId    = checkData.Item3;
                        throw new UniqueNickInUseException(profileId, userId);
                    }
                    else
                    {
                        throw new UserExistsException(userModel); //user exist... need to throw profileid due to GP
                    }
                }
            }
            else if (register.profile?.Uniquenick != null)
            {
                var checkData = await profileRepository.CheckUniqueNickInUse(register.profile.Uniquenick, register.profile.Namespaceid, register.user.Partnercode);

                if (checkData.Item1)
                {
                    throw new UniqueNickInUseException(null);
                }
            }
            if (userModel != null)
            {
                if ((userId.HasValue && userId.Value != userModel.Id) || userModel.Password.CompareTo(register.password) != 0)
                {
                    throw new UserExistsException(userModel); //user exist... need to throw profileid due to GP
                }
                response.user = userModel;
            }
            else
            {
                //if OK, create user, and profile
                userModel             = new User();
                userModel.Email       = register.user.Email;
                userModel.Partnercode = register.user.Partnercode;
                userModel.Password    = register.password;

                response.user = (await userRepository.Create(userModel));
            }



            if (register.profile != null)
            {
                Profile profileModel = new Profile();
                profileModel = register.profile;

                profileModel.Userid = response.user.Id;
                profileModel        = await profileRepository.Create(profileModel);

                response.profile = profileModel;
            }

            //send registration email

            return(response);
        }
Beispiel #7
0
 public Profile Create(Profile newProfile)
 {
     return(_repo.Create(newProfile));
 }
 public async Task <Profile> Register([FromBody] Profile profile)
 {
     return(await _repo.Create(profile));
 }
        public int RegisterProfile(RegisterDataContract registerData)
        {
            int profileId = 0;
            using (ProfileRepository profileRepo = new ProfileRepository(new ChatDBDataContext()))
            {
                List<tbl_ChatUserProfile> profiles = profileRepo.Get();
                if (!ServiceUtils.IsExist<tbl_ChatUserProfile>(profiles, registerData.EmailAddress))
                {
                    tbl_ChatUserProfile profile = new tbl_ChatUserProfile
                    {
                        Address = registerData.Address,
                        EmailAddess = registerData.EmailAddress,
                        FullName = registerData.FullName,
                        PhoneNumber = registerData.PhoneNumber
                    };
                    profileRepo.Create(profile);
                    profileRepo.Save();

                    profileId = profileRepo.Get(registerData.EmailAddress).id;
                }
                else
                    throw new Exception("Profile Exists");
            }
            return profileId;
        }