public FamilyMember CreateMember([FromBody] FamilyMember member)
        {
            if (member == null)
            {
                throw new InvalidParameterException("Invalid parameters!");
            }

            if (_currentUserService.MemberType != MemberType.Admin && _currentUserService.MemberType != MemberType.Parent)
            {
                throw new UnauthorizedAccessException();
            }

            return(_familyService.AddMember(member));
        }
Beispiel #2
0
        /// <summary>
        /// Sign ups a new family.
        /// </summary>
        /// <param name="signUp">The sign up.</param>
        /// <returns>The auth response.</returns>
        public AuthResponse SignUp(SignUp signUp)
        {
            var familyMember = new FamilyMember();

            familyMember.Firstname  = signUp.Firstname;
            familyMember.Lastname   = signUp.Lastname;
            familyMember.Zipcode    = signUp.Zipcode;
            familyMember.MemberType = signUp.MemberType;
            familyMember.HasTrial   = signUp.HasTrial;

            if (!string.IsNullOrEmpty(signUp.PromoCode))
            {
                familyMember.PromoCode = signUp.PromoCode.ToUpper();
            }
            else
            {
                familyMember.PromoCode = null;
            }


            if (signUp.MemberType == MemberType.Parent)
            {
                familyMember.PhoneNumber = signUp.PhoneNumber;
            }

            var user = new User {
                Email = signUp.Email, Password = signUp.Password, FamilyID = signUp.FamilyID.Equals(0) ? 0 : signUp.FamilyID
            };

            familyMember.User = user;

            var member = _familyService.AddMember(familyMember);


            if (member == null)
            {
                return(null);
            }
            var authResponse = new AuthResponse {
                Firstname = member.Firstname, Lastname = member.Lastname, ProfileUrl = member.ProfileImageUrl, MemberType = member.MemberType, FamilyName = member.User.Family.Name, FamilyId = member.User.FamilyID, FamilyMemberId = member.Id, FamilyUrl = member.User.Family.UniqueName, AccessToken = string.Empty
            };

            return(authResponse);
        }