Example #1
0
        public void Register(User u, Address a)
        {
            u.Validate();
            checkForExistingEmail(u, u.Email);
            checkForExistingUsername(u, u.Username);
            checkPasswordFormat(u.Password);
            u.Password    = EncryptionHelper.GetMD5(u.Password);
            u.PhoneNumber = PhoneHelper.GetPhoneWithCorrectFormat(u.PhoneNumber);
            EmailHelper.CheckEmailFormat(u.Email);
            a.Validate();
            Address userAddress = getEqualAddress(a);

            u.Address = userAddress;
            u.Role    = 1;
            Order order = new Order();

            order.Status = OrderStatuses.WAITING_FOR_ADDRESS;
            order.UserId = u.Id;
            userRepository.Add(u);
            orderRepository.Add(order);
        }
Example #2
0
        public void Modify(User user)
        {
            User u = this.Get(user.Id);

            if (u != null)
            {
                string      pass = u.Password;
                Address     add  = u.Address;
                List <User> all  = userRepository.GetAll();
                user.Validate();
                checkForExistingEmail(user, user.Email);
                checkForExistingUsername(user, user.Username);
                user.PhoneNumber = PhoneHelper.GetPhoneWithCorrectFormat(user.PhoneNumber);
                user.Password    = pass;
                user.Address     = add;
                EmailHelper.CheckEmailFormat(user.Email);
                userRepository.Update(user);
            }
            else
            {
                throw new NotExistingUserException();
            }
        }