public void Delete(int id) { RetailCustomer customer = db.RetailCustomers.Find(id); db.RetailCustomers.Remove(customer); db.SaveChanges(); }
public async Task <IActionResult> AddAsync([FromBody] RetailCustomer newCustomer) { _customerContext.RetailCustomer.Add(newCustomer); await _customerContext.SaveChangesAsync(); return(Ok(newCustomer)); }
static void TestRetailCustomer() { Console.WriteLine("Testing RetailCustomer constructor."); RetailCustomer retailcus1 = new RetailCustomer("John", "Smith", "*****@*****.**", "(541)-123-4567"); RetailCustomer retailcus2 = new RetailCustomer("Jon", "Snow", "*****@*****.**", "(123)-456-7890"); Console.WriteLine("Expecting John Smith, [email protected] ph: (541)-123-4567.\n" + retailcus1.GetDisplayText()); Console.WriteLine("Expecting Jon Snow, [email protected] ph: (123)-456-7890.\n" + retailcus2.GetDisplayText()); }
public void PrintCustomerID() { RetailCustomer retailCustomerInstance = new RetailCustomer(); //RetailCustomer class is not deriving from Customer class, hence it is an error //to access Customer class protected ID member, using the retailCustomerInstance //Console.WriteLine(retailCustomerInstance.ID); //Error //Both these below lines also produce the same Error //Console.WriteLine(this.ID); // Error //Console.WriteLine(base.ID); // Error }
// This constructor requires the two original implementations, and an ICustomerContext. // The ICustomerContext allows requesting information about public CustomerProcessProxy( RetailCustomer retail, CommercialCustomer commercial, ICustomerContext context) { this.retail = retail; this.commercial = commercial; // Important note: in the constructor you should ONLY store incoming dependencies, // but never use them. That's why we won't call context.IsRetailCustomer here. this.context = context; }
public IHttpActionResult GetById(int id) { RetailCustomer customer = _retailCustomerService.GetById(id); if (customer == null) { return(NotFound()); } return(Ok(customer)); }
// RetailCustomer Class Test static void TestRetailCustomer() { Console.WriteLine("Testing Retail Class"); RetailCustomer retailcust1 = new RetailCustomer("Aaron", "Baker", "*****@*****.**", "(555) 555-5555"); RetailCustomer retailcust2 = new RetailCustomer("Cathi", "Davis", "*****@*****.**", "(555) 777-7777"); Console.WriteLine("Expecting Aaron Baker, [email protected] ph: (555) 555-5555 \n" + retailcust1.GetDisplayText()); Console.WriteLine("Expecting Cathi Davis, [email protected] ph: (555) 777-7777 \n" + retailcust2.GetDisplayText()); Console.WriteLine(); }
public async Task <IActionResult> GetbyIdAsync([FromRoute] string id) { //TODO return not found error // var customerItem = await _customerContext.RetailCustomer.SingleOrDefaultAsync(i => i.Id == customerToUpdate.Id); // if (customerItem == null) // { // return NotFound(new { Message = $"Item with id {customerToUpdate.Id} not found." }); // } RetailCustomer customer = await _customerContext.RetailCustomer.Where(x => x.Id == id).SingleOrDefaultAsync(); return(Ok(customer)); }
static void TestRCustomer() { RetailCustomer rC = new RetailCustomer("Mickey", "Mouse", "*****@*****.**", "555-555-5555"); // Creates new retail customer Console.WriteLine("Testing the overloaded constructor"); Console.WriteLine("Expecting Mickey Mouse [email protected] with 555-555-5555 phone number " + rC); // rC works because we overrode ToString Console.WriteLine("Testing setters"); rC.Phone = "555-555-5555"; Console.WriteLine("Expecting 555-555-5555 " + rC.Phone); Console.WriteLine("Testing getters"); Console.WriteLine("Expecting 555-555-5555" + " " + rC.Phone); }
static void TestCustomerGetters() { Customer c1 = new Customer("Nohm", "Chomskey", "*****@*****.**"); WholesaleCustomer ws = new WholesaleCustomer(); RetailCustomer rs = new RetailCustomer(); Console.WriteLine("Testing getters"); Console.WriteLine("First name. Expecting Nohm. " + c1.FirstName); Console.WriteLine("Last name. Expecting Chomskey. " + c1.LastName); Console.WriteLine("Email. Expecting [email protected]. " + c1.Email); Console.WriteLine("Company name. Expecting Frank's Haircutting. " + ws.Company); Console.WriteLine("Home phone number. Expecting 5416669876. " + rs.HomePhone); Console.WriteLine(); }
static void TestCustomerToString() { Customer c1 = new Customer("Nohm", "Chomskey", "*****@*****.**"); WholesaleCustomer ws = new WholesaleCustomer(); RetailCustomer rs = new RetailCustomer(); Console.WriteLine("Testing ToString"); Console.WriteLine("Expecting Nohm, Chomskey, [email protected]. " + c1.GetDisplayText()); Console.WriteLine("Getting Nohm, Chomskey, [email protected]. " + c1.ToString()); Console.WriteLine("Testing WholesaleCustomer ToString and RetailCustomer ToString."); Console.WriteLine("Expecting default values."); Console.WriteLine(ws.ToString()); Console.WriteLine(rs.ToString()); Console.WriteLine(); }
public ActionResult Edit(RetailCustomer customer) { try { customer.ModifiedBy = Convert.ToInt32(Session["UserId"].ToString()); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Base_URL); HttpResponseMessage response = client.PutAsJsonAsync("customer", customer).Result; response.EnsureSuccessStatusCode(); return(Json("Customer Updated", JsonRequestBehavior.AllowGet)); } catch { return(Json("Failed", JsonRequestBehavior.AllowGet)); } }
public async Task <IActionResult> UpdateAsync([FromBody] RetailCustomer customerToUpdate) { // var customerItem = await _customerContext.RetailCustomer.SingleOrDefaultAsync(i => i.Id == customerToUpdate.Id); //TODO return not found error // if (customerItem == null) // { // return NotFound(new { Message = $"Item with id {customerToUpdate.Id} not found." }); // } _customerContext.RetailCustomer.Update(customerToUpdate); await _customerContext.SaveChangesAsync(); return(Ok(customerToUpdate)); }
static void TestCustomerPolymorphism() { Console.WriteLine("Polymorphism tested with GetDisplayText"); Customer cust1 = new Customer("Jake", "Last", "*****@*****.**"); WholesaleCustomer wholecust1 = new WholesaleCustomer("Brandon", "Bobs", "*****@*****.**", "Bobs Motors"); RetailCustomer retailcust1 = new RetailCustomer("Aaron", "Baker", "*****@*****.**", "(555) 555-5555"); Console.WriteLine("GetDisplay Text from Customer Class"); Console.WriteLine("Expecting Jake Last, [email protected] \n" + cust1.GetDisplayText()); Console.WriteLine("GetDisplayText from WholesaleCustomer Class"); Console.WriteLine("Expecting Expecting Brandon Bobs, bbobs@bobsmotors (Bobs Motors) \n" + wholecust1.GetDisplayText()); Console.WriteLine("GetDisplayText from RetailCustomer Class"); Console.WriteLine("Expecting Aaron Baker, [email protected] ph: (555) 555-5555 \n" + retailcust1.GetDisplayText()); Console.WriteLine(); }
public JsonResult GetById(int id) { RetailCustomer customer = new RetailCustomer(); try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Base_URL); HttpResponseMessage response = client.GetAsync("customer/" + id).Result; response.EnsureSuccessStatusCode(); customer = response.Content.ReadAsAsync <RetailCustomer>().Result; return(Json(customer, JsonRequestBehavior.AllowGet)); } catch { return(Json(false, JsonRequestBehavior.AllowGet)); } }
static void TestCustomerSetters() { Customer c1 = new Customer("Nohm", "Chomskey", "*****@*****.**"); WholesaleCustomer ws = new WholesaleCustomer(); RetailCustomer rs = new RetailCustomer(); Console.WriteLine("Testing setters"); c1.FirstName = "Kyle"; c1.LastName = "Normand"; c1.Email = "*****@*****.**"; ws.Company = "Noble Barns Emporium"; rs.HomePhone = "5419999999"; Console.WriteLine("Expecting Kyle, Normand, [email protected]."); Console.WriteLine("Getting " + c1.GetDisplayText()); Console.WriteLine("Expecting Noble Barns Emporium and 5419999999"); Console.WriteLine("Getting " + ws.Company + " and " + rs.HomePhone); Console.WriteLine(); }
static void TestCustomerList2() { Console.WriteLine("Testing retail and wholesale in same list."); CustomerList2 cList = new CustomerList2(); WholesaleCustomer wc1 = new WholesaleCustomer("Amy", "Johnson", "*****@*****.**", "LCC"); RetailCustomer rc1 = new RetailCustomer("Juan", "Lopez", "*****@*****.**", "(541)-123-4567"); cList.Add(wc1); cList += rc1; Console.WriteLine("Expecting list containing a wholesale customer, 'Amy Johnson', and a retail customer, 'Juan Lopez'\n" + cList); string allFirstNames = ""; foreach (Customer c in cList) { allFirstNames = allFirstNames + " " + c.FirstName; } Console.WriteLine(allFirstNames); }
public void Create(RetailCustomer customer) { if (customer.Address != null && customer.Region != null && customer.MobileNo != null && customer.Gender != null) { var host = Dns.GetHostEntry(Dns.GetHostName()); var ipList = (from ip in host.AddressList where ip.AddressFamily == AddressFamily.InterNetwork select ip.ToString()).ToList(); var ipAddress = ipList[0].ToString(); customer.CreatedDate = DateTime.UtcNow; customer.CreatedFrom = ipAddress; db.RetailCustomers.Add(customer); db.SaveChanges(); } else { throw new Exception("Required field can't be empty"); } }
static void TestCustomerConstructors() { Customer c1 = new Customer(); WholesaleCustomer ws = new WholesaleCustomer(); RetailCustomer rs = new RetailCustomer(); Customer c2 = new Customer("Nohm", "Chomskey", "*****@*****.**"); WholesaleCustomer ws2 = new WholesaleCustomer("Nohm", "Chomskey", "*****@*****.**", "Ben's Boxing"); RetailCustomer rs2 = new RetailCustomer("Nohm", "Chomskey", "*****@*****.**", "5415555555"); Console.WriteLine("Testing both constructors"); Console.WriteLine("Default constructor. Expecting default values. " + c1.GetDisplayText()); Console.WriteLine("Overloaded constructor. Expecting Nohm Chomskey, nohmchomskey.com. "); Console.WriteLine("Getting " + c2.GetDisplayText()); Console.WriteLine("Testing WholesaleCustomer's constructors and RetailCustomer's constructors."); Console.WriteLine("Expecting default values."); Console.WriteLine("WholesaleCustomer: " + ws.GetDisplayText() + " RetailCustomer: " + rs.GetDisplayText()); Console.WriteLine("Expecting Nohm, Chomskey, [email protected], Ben's boxing and Nohm, Chomskey, [email protected], 5415555555"); Console.WriteLine("Overloaded WholesaleCustomer: " + ws2.GetDisplayText() + " Overloaded RetailCustomer: " + rs2.GetDisplayText()); Console.WriteLine(); }
// CustomerList2 Combo Tests static void TestCustomerList2Combo() { Console.WriteLine("Testing Wholesale and Retail in same list"); CustomerList2 cList2 = new CustomerList2(); // Add wholesale customers to the list WholesaleCustomer wholecust1 = new WholesaleCustomer("Brandon", "Bobs", "*****@*****.**", "Bobs Motors"); cList2.Add(wholecust1); WholesaleCustomer wholecust2 = new WholesaleCustomer("Mary", "Scampi", "*****@*****.**", "Scampi Shrimp"); cList2.Add(wholecust2); // Add retail customers to the list w/overloaded operators RetailCustomer retailcust1 = new RetailCustomer("Aaron", "Baker", "*****@*****.**", "(555) 555-5555"); cList2 += retailcust1; RetailCustomer retailcust2 = new RetailCustomer("Cathi", "Davis", "*****@*****.**", "(555) 777-7777"); cList2 += retailcust2; Console.WriteLine("Expecting list of 4 customers, 1st 2 wholesale, next 2 retail \n" + cList2); Console.WriteLine(); Console.WriteLine("Testing foreach"); Console.WriteLine("All first names. Expecting: Brandon Mary Aaron Cathi"); string allFirstNames = ""; //foreach loop to get all first names in both lists, then combine foreach (Customer cust in cList2) { allFirstNames = allFirstNames + cust.FirstName + " "; } Console.WriteLine(allFirstNames); Console.WriteLine(); Console.WriteLine("Testing Remove and - operator"); cList2.Remove(wholecust2); cList2 -= retailcust2; Console.WriteLine("Expecting 1 retail and 1 wholesale \n" + cList2); }
private void btnQuery_Click(object sender, EventArgs e) { RetailCustomer ro = new RetailCustomer(); if (!chbIsCDNo.Checked) //没有选中光盘号查询 { string strWhere = "Where (CustomerType = '2' or CustomerType = '3')"; if (!String.IsNullOrEmpty(txtCustomerName.Text.Trim())) { strWhere += " and CustomerName like '%" + txtCustomerName.Text.Trim() + "%'"; } if (!(cbxProvinceCode.SelectedValue == null)) { strWhere += " and ProvinceCode = '" + cbxProvinceCode.SelectedValue.ToString() + "'"; } if (!String.IsNullOrEmpty(txtAddress.Text.Trim())) { strWhere += " and Address like '%" + txtAddress.Text.Trim() + "%'"; } if (!String.IsNullOrEmpty(txtPhoneNumber.Text.Trim())) { strWhere += " and PhoneNumber like '%" + txtPhoneNumber.Text.Trim() + "%'"; } if (!String.IsNullOrEmpty(txtURL.Text.Trim())) { strWhere += " and URL like '%" + txtURL.Text.Trim() + "%'"; } dgvRetailCustomer.DataSource = ro.GetDataTable("Customer", strWhere); } if (chbIsCDNo.Checked) //选中光盘号查询 { if (String.IsNullOrEmpty(txtCDNo.Text.Trim())) { MessageBox.Show("请输入光盘号!", "软件提示"); txtCDNo.Focus(); return; } string strSql = "Select Customer.* From Customer,SaleOrderBill,SaleCDRecord,SaleConsignBill Where SaleCDRecord.SaleConsignBillId = SaleConsignBill.Id and SaleConsignBill.SaleBillNo = SaleOrderBill.SaleBillNo and SaleOrderBill.CustomerId = Customer.CustomerId"; dgvRetailCustomer.DataSource = ro.GetDataTable(strSql); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RetailCustomer customer = new RetailCustomer(); try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Base_URL); HttpResponseMessage response = client.GetAsync("customer/" + id).Result; response.EnsureSuccessStatusCode(); customer = response.Content.ReadAsAsync <RetailCustomer>().Result; return(View(customer)); } catch { return(View("Index")); } }
public void Update(RetailCustomer customer) { _retailCustomerService.Update(customer); }
public void Create(RetailCustomer customer) { _retailCustomerService.Create(customer); }
static void TestCustomerExceptions() { Customer c1 = new Customer("Nohm", "Chomskey", "*****@*****.**"); WholesaleCustomer c2 = new WholesaleCustomer(); RetailCustomer c3 = new RetailCustomer(); Console.WriteLine("Testing customer set exceptions"); Console.WriteLine("Attempting to set first name, last name, and email to more than 30 characters, expecting an exception from each."); try { c1.FirstName = "11111111111111111111111111111111111111111111111111111111111111111111"; Console.WriteLine("Exception not caught."); } catch (Exception e) { Console.WriteLine("Exception caught with message " + e); } Console.WriteLine(); try { c1.LastName = "11111111111111111111111111111111111111111111111111111111111111111111"; Console.WriteLine("Exception not caught."); } catch (Exception e) { Console.WriteLine("Exception caught with message " + e); } Console.WriteLine(); try { c1.Email = "11111111111111111111111111111111111111111111111111111111111111111111@."; Console.WriteLine("Exception not caught."); } catch (Exception e) { Console.WriteLine("Exception caught with message " + e); } Console.WriteLine("Attempting to set Company name to more than 30 characters, and an invalid phone number expecting an exception from each."); try { c2.Company = "11111111111111111111111111111111111111111111111111111111111111111111"; Console.WriteLine("Exception not caught."); } catch (Exception e) { Console.WriteLine("Exception caught with message " + e); } try { c3.HomePhone = "David66666666."; Console.WriteLine("Exception not caught."); } catch (Exception e) { Console.WriteLine("Exception caught with message " + e); } Console.WriteLine(); }