コード例 #1
0
 public DTOResponse <DTOPet> Create(DTOPet createPetInfo)
 {
     return(_petDomain.Create(createPetInfo));
 }
コード例 #2
0
        public DTOResponse <DTOUser> Create(DTOCreateUser createUserInfo)
        {
            if (string.IsNullOrWhiteSpace(createUserInfo.Email) || string.IsNullOrWhiteSpace(createUserInfo.Password) || string.IsNullOrWhiteSpace(createUserInfo.ConfirmPassword))
            {
                return(new DTOResponse <DTOUser>()
                {
                    Code = 400,
                    Message = "Email, Password and Confirm Password are required!"
                });
            }

            var getUserResponse = GetUserByEmail(createUserInfo.Email);

            if (getUserResponse.Code == 200)
            {
                return(new DTOResponse <DTOUser>()
                {
                    Code = 400,
                    Message = "This user email is already registered!"
                });
            }

            if (createUserInfo.Password != createUserInfo.ConfirmPassword)
            {
                return(new DTOResponse <DTOUser>()
                {
                    Code = 400,
                    Message = "The password and confirm password dont match!"
                });
            }

            if (!createUserInfo.HasAcceptedTermsAndPrivacyPolice)
            {
                return(new DTOResponse <DTOUser>()
                {
                    Code = 400,
                    Message = "The user must accept Terms and Privacy police!"
                });
            }

            createUserInfo.User.Email       = createUserInfo.Email;
            createUserInfo.User.AccessLevel = UserAccessLevel.Normal;

            var userModel = createUserInfo.User.ToModel();

            var passwordHash = SecurePasswordHasher.Hash(createUserInfo.Password);

            userModel.PasswordHash = passwordHash;

            _userCollection.InsertOne(userModel);

            getUserResponse = GetUserByEmail(createUserInfo.Email);
            var existingUser = getUserResponse.Data;

            createUserInfo.Pet.UserId = existingUser.Id;

            if (createUserInfo.Pet != null)
            {
                _petDomain.Create(createUserInfo.Pet);
            }

            LoadUserInfo(existingUser);

            return(new DTOResponse <DTOUser>()
            {
                Code = 200,
                Data = existingUser
            });
        }