/// <summary>
        /// adds a new customer
        /// </summary>
        /// <param name="customerDTO"></param>
        /// <returns></returns>
        public ICustomMessage RegisterCustomer(ICustomerDTO customerDTO)
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Customer, CustomerDTO>());
            var mapper = config.CreateMapper();

            ICustomMessage msg = new CustomMessage();

            IList <Customer> customers = _db.GetCustomers();

            if (FindCustomer(customerDTO) != null)
            {
                msg.Message = "Customer is already registered";
                return(msg);
            }
            var customer = new Customer
            {
                Customer_email     = customerDTO.Customer_email,
                Customer_firstname = customerDTO.Customer_firstname,
                Customer_lastname  = customerDTO.Customer_lastname,
                Customer_mobile    = customerDTO.Customer_mobile,
                Customer_password  = Encryption.Encrypt(customerDTO.Customer_password),
                Customer_status    = customerDTO.Customer_status
            };

            msg.Code = _db.AddCustomer(customer);
            if (msg.Code >= 0)
            {
                msg.Message = "User added";
            }
            else
            {
                msg.Message = "error in adding user";
            }
            return(msg);
        }
        //TODO: take a NewCustomer Type instead ? for cleaner implementation
        public bool AddCustomer(string firname, string surname, string email, DateTime dateOfBirth, int companyId)
        {
            if (IsEntryValid(firname, surname, email, dateOfBirth, companyId))
            {
                var newCustomer = NewCustomerFactory(firname, surname, email, dateOfBirth, companyId);

                if (IsCreditLimitQualified(newCustomer))
                {
                    //TODO: Maybe have a return type to indicate Add method is successful allowing:
                    //return _customerDataAccess.AddCustomer(newCustomer);
                    _customerDataAccess.AddCustomer(newCustomer);
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
        public bool AddCustomer(Customer customerInfo)
        {
            if (!ValidateCustomInfo(customerInfo))
            {
                return(false);
            }

            var company = _companyRepository.GetById(customerInfo.CompanyId);

            var customer = InitCustomer(customerInfo, company);

            this.GetCustomerCredit(company, customer);

            if (CustomerUtils.IsLimtedCredit(customer))
            {
                return(false);
            }

            _customerDataAccess.AddCustomer(customer);

            return(true);
        }