Exemplo n.º 1
0
        public CustomerErrorCodes AddCustomer(string name, string adress, string dateOfBirthDDMMYYYY, [Optional] int parentCustomerID)
        {
            DateTime dateOfBirth;
            bool     correctDate = DateTime.TryParseExact(dateOfBirthDDMMYYYY, "ddMMyyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateOfBirth);

            if (correctDate == true)
            {
                TimeSpan yearsOld = DateTime.Today - dateOfBirth;
                if (yearsOld.TotalDays < 5475)
                {
                    var parent = customerManager.GetCustomer(parentCustomerID);
                    if (parent == null)
                    {
                        return(CustomerErrorCodes.CustomerToYoungMustHaveParent);
                    }
                    else
                    {
                        customerManager.AddCustomer(name, adress, dateOfBirth, parent);
                    }
                    return(CustomerErrorCodes.okUnderageCustomerWithParentAdded);
                }
                else
                {
                    customerManager.AddCustomer(name, adress, dateOfBirth);
                }
                return(CustomerErrorCodes.ok);
            }
            else
            {
                return(CustomerErrorCodes.CustomerDateOfBirthIsIncorrect);
            }
        }
Exemplo n.º 2
0
        private static void addingCustomerFeature()
        {
            Customer bk = new Customer();

            bk.CustomerID   = GetData.getNumber("Enter the ID of the Customer");
            bk.CustomerName = GetData.getString("Enter the Name of the Customer");
            bk.Address      = GetData.getString("Enter the Address of the Customer");
            bk.Salary       = GetData.getDouble("Enter the Salary of the Customer");
            try
            {
                bool result = mgr.AddCustomer(bk);
                if (!result)
                {
                    Console.WriteLine("No more customers could be added");
                }
                else
                {
                    Console.WriteLine($"Customer by name {bk.CustomerName} is added successfully to the database");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 3
0
        public IActionResult Post([FromBody] Customer customer)
        {
            if (customer == null)
            {
                return(BadRequest());
            }

            var id = _customerManager.AddCustomer(customer);

            if (id <= 0)
            {
                ModelState.AddModelError(nameof(Customer),
                                         "Oops, Customer already exists!");

                // return 422 - Unprocessable Entity
                return(new UnprocessableEntityObjectResult(ModelState));
            }
            else
            {
                customer.Id = id;

                return(CreatedAtRoute("Get",
                                      new { id },
                                      customer));
            }
        }
Exemplo n.º 4
0
 public IHttpActionResult AddCustomer(Customer customer)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(_customerManager.AddCustomer(customer)));
 }
Exemplo n.º 5
0
        static void InitializeComponent()
        {
            menu = string.Format($"~~~ CUSTOMER MANAGEMENT ~~~\n1. ADD CUSTOMER\n2. UPDATE CUSTOMER\n3. DELETE CUSTOMER\n4. SEARCH BY NAME\nPRESS ANY OTHER KEY TO EXIT\n");
            int size = GetData.getNumber("Enter the size of Customer Array");

            mgr = CustomerFactoryComponent.GetComponent(size);
            mgr.AddCustomer(new Customer {
                CustomerID = 01, CustomerName = "vidya", Address = "Mysore", Salary = 12000
            });
            mgr.AddCustomer(new Customer {
                CustomerID = 02, CustomerName = "ram", Address = "Bangalore", Salary = 15000
            });
            mgr.AddCustomer(new Customer {
                CustomerID = 03, CustomerName = "john", Address = "Mangalore", Salary = 13500
            });
            mgr.AddCustomer(new Customer {
                CustomerID = 04, CustomerName = "nick", Address = "Mysore", Salary = 12800
            });
        }
Exemplo n.º 6
0
        static void InitializeComponent()
        {
            menu = string.Format($"~~~~~~~ CUSTOMER MANAGEMENT ~~~~~~~\n1. ADD CUSTOMER\n2. UPDATE CUSTOMER\n3. DELETE CUSTOMER\n4. SEARCH BY NAME\nPRESS ANY OTHER KEY TO EXIT\n");
            int size = GetData.getNumber("Enter the size of Customer Array");

            mgr = CustomerFactoryComponent.GetComponent(size);
            mgr.AddCustomer(new Customer {
                CustomerID = 123, CustomerName = "cvp", Address = "pkd", Salary = 12000
            });
            mgr.AddCustomer(new Customer {
                CustomerID = 124, CustomerName = "jk", Address = "hyd", Salary = 15000
            });
            mgr.AddCustomer(new Customer {
                CustomerID = 125, CustomerName = "ry", Address = "jrg", Salary = 13500
            });
            mgr.AddCustomer(new Customer {
                CustomerID = 126, CustomerName = "raj", Address = "in", Salary = 12800
            });
        }
Exemplo n.º 7
0
        static void InitializeComponent()
        {
            menu = string.Format($"~~~~~~~ CUSTOMER MANAGEMENT ~~~~~~~\n1. ADD CUSTOMER\n2. UPDATE CUSTOMER\n3. DELETE CUSTOMER\n4. SEARCH BY NAME\nPRESS ANY OTHER KEY TO EXIT\n");
            int size = GetData.getNumber("Enter the size of Customer Array");

            mgr = CustomerFactoryComponent.GetComponent(size);
            mgr.AddCustomer(new Customer {
                CustomerID = 901, CustomerName = "jyothsna", Address = "hyd", Salary = 60000
            });
            mgr.AddCustomer(new Customer {
                CustomerID = 902, CustomerName = "shiri", Address = "tirupathi", Salary = 70000
            });
            mgr.AddCustomer(new Customer {
                CustomerID = 903, CustomerName = "teju", Address = "banglore", Salary = 80000
            });
            mgr.AddCustomer(new Customer {
                CustomerID = 904, CustomerName = "shreya", Address = "mysore", Salary = 90000
            });
        }
        public CustomerStatusCodes AddCustomer(string customerName, string customerAdress, string birthDate, int debt, Customer guardian)
        {
            var existingCustomer = customerManager.GetCustomerByCustomerName(customerName);

            if (existingCustomer != null)
            {
                return(CustomerStatusCodes.CustomerAldreadyExist);
            }
            if (CheckValidDate(birthDate) == false)
            {
                return(CustomerStatusCodes.InvalidBirthDate);
            }
            if (GetAge(birthDate) < 15)
            {
                customerManager.AddCustomer(customerName, customerAdress, birthDate, debt, guardian);
                return(CustomerStatusCodes.CustomerIsJuvenile);
            }

            customerManager.AddCustomer(customerName, customerAdress, birthDate, debt, null);
            return(CustomerStatusCodes.Ok);
        }
Exemplo n.º 9
0
        public AddCustomerStatusCodes AddCustomer(int customerNumber, string customerName, string birthDate, string address, Customer guardian)
        {
            decimal newDebt          = 0;
            var     existingCustomer = customerManager.GetCustomerByCustomerNumber(customerNumber);

            if (existingCustomer != null)
            {
                return(AddCustomerStatusCodes.CustomerAlreadyExist);
            }
            if (ValidateBirthDate(birthDate) == false)
            {
                return(AddCustomerStatusCodes.InvalidBirthDate);
            }
            if (GetAge(birthDate) < 15)
            {
                customerManager.AddCustomer(customerNumber, customerName, birthDate, address, newDebt, guardian, false);
                customerManager.SetCustomerAsGuardian(guardian, true);
                return(AddCustomerStatusCodes.CustomerIsMinor);
            }

            customerManager.AddCustomer(customerNumber, customerName, birthDate, address, newDebt, null, false);
            return(AddCustomerStatusCodes.Ok);
        }
Exemplo n.º 10
0
        public AddCustomerErrorCodes AddCustomer(int customerNumber, string customerIDNumber)
        {
            if (string.IsNullOrEmpty(customerIDNumber))
            {
                return(AddCustomerErrorCodes.ThereIsNoIDNumber);
            }
            if (ValidateISBN(customerIDNumber) == false)
            {
                return(AddCustomerErrorCodes.IDNumberNotValid);
            }

            customerManager.AddCustomer(customerNumber, customerIDNumber);
            return(AddCustomerErrorCodes.Ok);
        }
        public async Task <IActionResult> Create(CustomerAddDto model)
        {
            if (ModelState.IsValid)
            {
                Customer customer = _mapper.Map <Customer>(model);

                await _customerManager.AddCustomer(customer);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(model));
            }
        }
Exemplo n.º 12
0
        /* public bool AddCustomer(string customerName, string customerAdress, string customersDateOfBirth, int customerDebt,int customerID)
         * {
         *   var exsitingCustomer = customerManager.GetCustomerByCustomerID(customerID);
         *   if (exsitingCustomer != null)
         *       return false;
         *   customerManager.AddCustomer(customerName, customerAdress, customersDateOfBirth, customerDebt);
         *   return true;
         * }*/

        public ErrorCodesAddCustomer AddCustomer(string customerName, string customerAdress, string customersDateOfBirth, int customerDebt, bool customerActiveLoan, int customerID)
        {
            var existingCustomer = customerManager.GetCustomerByCustomerID(customerID);

            if (existingCustomer != null)
            {
                return(ErrorCodesAddCustomer.CustomerAlreadyExists);
            }
            if (GetAgeCustomer(customersDateOfBirth) < 15)
            {
                return(ErrorCodesAddCustomer.CustomerIsToYoung);
            }
            customerManager.AddCustomer(customerName, customerAdress, customersDateOfBirth, customerDebt, customerActiveLoan);
            return(ErrorCodesAddCustomer.Ok);
        }
Exemplo n.º 13
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            if (_editMode)
            {
                Customer oldCustomer = _customer;

                Customer newCustomer = new Customer()
                {
                    Email       = TxtEmail.Text,
                    FirstName   = TxtFirstName.Text,
                    LastName    = TxtLastName.Text,
                    PhoneNumber = TxtPhoneNumber.Value.ToString()
                };

                try
                {
                    if (_customerManager.EditCustomerDetails(oldCustomer, newCustomer))
                    {
                        MessageBox.Show("Update Successful", "Success", MessageBoxButton.OK);
                        this.NavigationService?.Navigate(new pgCustomerList());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\n\n" + ex.InnerException?.Message);
                }
            }

            if (_addMode)
            {
                try
                {
                    if (_customerManager.AddCustomer(new Customer()
                    {
                        FirstName = TxtFirstName.Text,
                        LastName = TxtLastName.Text,
                        Email = TxtEmail.Text,
                        PhoneNumber = TxtPhoneNumber.Value.ToString()
                    }))
                    {
                        MessageBox.Show("Customer Added", "Success", MessageBoxButton.OK);
                        if (_fromCart)
                        {
                            try
                            {
                                _customer = _customerManager.GetCustomerByEmail(TxtEmail.Text);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message);
                            }
                        }
                    }

                    if (MessageBox.Show("Would you like add another Customer?", "Add Another?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        TxtFirstName.Text   = "";
                        TxtLastName.Text    = "";
                        TxtEmail.Text       = "";
                        TxtPhoneNumber.Text = "";
                        TxtFirstName.Focus();
                    }
                    else
                    {
                        if (_fromCart)
                        {
                            this.NavigationService?.Navigate(new PgCart(_user, _customer, true));
                        }
                        else
                        {
                            this.NavigationService?.Navigate(new pgCustomerList());
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\n\n" + ex.InnerException?.Message);
                }
            }
        }
        // POST: api/Cutomer
        public IHttpActionResult Post([FromBody] Customers customer)
        {
            var response = _ICustomerManager.AddCustomer(customer);

            return(Ok(response));
        }
Exemplo n.º 15
0
        public async Task <RegisterStatus> AddCustomer(UserModel userModel, string password)
        {
            var user = _mapper.Map <User>(userModel);

            return(await _customerManager.AddCustomer(user, password));
        }