static List <CustomerModel> LoadCustomers(string customerDataFile)
 {
     // In a real application, the data would come from an external source,
     // but for this demo let's keep things simple and use a resource file.
     using (Stream stream = GetResourceStream(customerDataFile))
         using (XmlReader xmlRdr = new XmlTextReader(stream))
             return
                 ((from customerElem in XDocument.Load(xmlRdr).Element("customers").Elements("customer")
                   select CustomerModel.CreateCustomer(
                       (double)customerElem.Attribute("totalSales"),
                       (string)customerElem.Attribute("firstName"),
                       (string)customerElem.Attribute("lastName"),
                       (bool)customerElem.Attribute("isCompany"),
                       (string)customerElem.Attribute("email")
                       )).ToList());
 }
Esempio n. 2
0
 public ActionResult createCustomer()
 {
     if (Session["loggedInState"] == null)
     {
         return(Redirect("/403.html"));
     }
     else
     {
         int      id     = int.Parse(Request.Form["newAddress"]);
         String   name   = Request.Form["newClientName"];
         Customer client = new Customer();
         client.Name       = name;
         client.Address_ID = id;
         var cm = new CustomerModel();
         cm.CreateCustomer(client);
         return(Redirect("Customer"));
     }
 }
Esempio n. 3
0
        //// GET: Customer
        //public ActionResult GetCustomers()
        //{
        //    // If logged in
        //    bool state = (bool)Session["loggedInState"];
        //    if (state == true)
        //    {
        //        // Creates models
        //        var addressModel = new AddressModel();
        //        var customerModel = new CustomerModel();

        //        // Gets the complete list
        //        var customerList = customerModel.ListCustomers();

        //        // Attaches associated address to customer
        //        foreach (var customer in customerList)
        //        {
        //            Address address = null;
        //            if (customer.Address_ID != 0)
        //            {
        //                address = addressModel.SearchAddress(customer.Address_ID);
        //            }

        //            // Appends object to address
        //            customer.Address = address;
        //        }

        //        // Return the CustomerList
        //        return View(customerList);
        //    }
        //    else
        //    {
        //        return Redirect("/403.html");
        //    }
        //}

        // Creates a new customer
        public int create(String name, int addressID)
        {
            // Establishes models
            CustomerModel customerModel = new CustomerModel();

            // Holds object placeholders
            Customer newCustomer = new Customer();

            // Stored details for the customer
            newCustomer.Name       = name;
            newCustomer.Address_ID = addressID;

            // Creates the customer
            int customerID = customerModel.CreateCustomer(newCustomer);

            // Return created department to view
            return(customerID);
        }
        public ReturnAllServices CreateCustomer([FromBody] CustomerModel customer)
        {
            ReturnAllServices ret = new ReturnAllServices();

            try
            {
                customer.CreateCustomer();
                ret.Result       = true;
                ret.ErrorMessage = string.Empty;
            }
            catch (Exception e)
            {
                ret.Result       = false;
                ret.ErrorMessage = "Error while trying to create a customer: " + e.Message;
            }

            return(ret);
        }
Esempio n. 5
0
 public IActionResult Create(CustomerModel customer)
 {
     customer.CreateCustomer();
     return(View());
 }