public int AddCustomer(Data.Entities.Customer customer)
        {
            _unitOfWork.CustomerRepository.AddCustomer(customer);
            _unitOfWork.Save();

            return(customer.CustomerId);
        }
        public bool Register(string email, string password)
        {
            bool returnValue = false;

            if (!IsCustomerExists(email))
            {
                try
                {
                    Data.Entities.Customer newCustomer = new Data.Entities.Customer()
                    {
                        Email = email,
                        HashPassword = PasswordHash.CreateHash(password)
                    };

                    _customerRepository.Add(newCustomer);

                    _unitOfWork.Commit();
                }
                catch (Exception exception)
                {
                    throw new FaultException(exception.Message);
                }

                returnValue = true;
            }

            return returnValue;
        }
Exemplo n.º 3
0
        public async Task <CustomerContext> AddNewCustomer(string email, string password)
        {
            var customer = new Data.Entities.Customer
            {
                Email     = email,
                Password  = password,
                CreatedAt = DateTime.Now,
                CreatedBy = 1,
                IsActive  = true
            };

            await _customerRepository.InsertAsync(customer);

            await _customerRepository.SaveAllAsync();

            await SendWelcomingMail(email);

            return(await GetCustomerById(customer.Id));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Post([FromBody] Customer customer)
        {
            if (customer == null)
            {
                return(BadRequest(new OperationStatus("Customer is not valid")));
            }

            var customerEntity = new Data.Entities.Customer
            {
                FirstName = customer.FirstName,
                LastName  = customer.LastName,
                Email     = customer.Email
            };

            var customerId = await _customerRepository.CreateCustomer(customerEntity).ConfigureAwait(false);;

            customer.Id = customerId;

            return(CreatedAtAction(nameof(GetById), new { id = customerId }, customer));
        }
        private void FindCustomer(string userName, string password)
        {
            _customerRepository.EnrollUnitOfWork(_unitOfWork);

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                throw new FaultException("Username and passwrod required.");
            }

            var customer = _customerRepository
                  .FindBy(c => c.Email == userName && PasswordHash.ValidatePassword(password, c.HashPassword));

            if (!customer.Any())
            {
                throw new FaultException("Wrong username or password.");
            }

            if (customer.First().IsDeleted)
            {
                throw new FaultException("That user is blocked. Contact with support.");
            }

            _actualLoggedCustomer = customer.First();
        }