public async Task <IActionResult> Edit(int id, [Bind("CustId,CustFirstName,CustSurName")] CafeCustomers cafeCustomers) { if (id != cafeCustomers.CustId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cafeCustomers); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CafeCustomersExists(cafeCustomers.CustId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cafeCustomers)); }
public async Task <IActionResult> PutCafeCustomers([FromRoute] int id, [FromBody] CafeCustomers cafeCustomers) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != cafeCustomers.CustId) { return(BadRequest()); } _context.Entry(cafeCustomers).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CafeCustomersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult CreateCustomer(CafeCustomers customer) { if (ModelState.IsValid) { AlertCreateCustomer(customer); } return(View()); }
public IActionResult EditCustomer(int id, [Bind("CustId,CustFirstName,CustSurName")] CafeCustomers customer) { if (id != customer.CustId) { return(NotFound()); } if (ModelState.IsValid) { AlertEditCustomer(id, customer); } return(View(customer)); }
public ActionResult Checkout(CafeCustomers customer) { //Validation of input fields if (ModelState.IsValid) { customer = _customerRepository.CreateCustomer(customer); return(RedirectToAction("CheckoutConfirmation", "CafeOrders", new { @customerId = customer.CustId })); } else { return(View()); } }
public CafeCustomers CreateCustomer(CafeCustomers customer) { //Gets last customers ID and adds by 1 CafeCustomers lastCustomer = _DbContext.CafeCustomers.LastOrDefault(c => c.CustId == c.CustId); if (lastCustomer != null) { customer.CustId = lastCustomer.CustId + 1; } else { customer.CustId = 1; } _DbContext.CafeCustomers.Add(customer); _DbContext.SaveChanges(); return(customer); }
// POST: api/customer/ private void AlertCreateCustomer(CafeCustomers customer) { string URI = "http://web.socem.plymouth.ac.uk/ISAD251/jharrison12/api/customer"; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpContent content = new StringContent("{\"custFirstName\":\"" + customer.CustFirstName.ToString() + "\",\"custSurName\":\"" + customer.CustSurName.ToString() + "\"}", Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(URI, content).Result; if (response.IsSuccessStatusCode == true) { ViewBag.Success = true; } } }
public async Task <IActionResult> Create([Bind("CustId,CustFirstName,CustSurName")] CafeCustomers cafeCustomers) { var LastEmployee = _context.CafeCustomers.OrderByDescending(c => c.CustId).FirstOrDefault(); if (LastEmployee == null) { cafeCustomers.CustId = 1; } else { cafeCustomers.CustId = LastEmployee.CustId + 1; } if (ModelState.IsValid) { _context.Add(cafeCustomers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cafeCustomers)); }
public async Task <IActionResult> PostCafeCustomers([FromBody] CafeCustomers cafeCustomers) { //Gets last customers ID and adds by 1 CafeCustomers lastCustomer = _context.CafeCustomers.LastOrDefault(c => c.CustId == c.CustId); if (lastCustomer != null) { cafeCustomers.CustId = lastCustomer.CustId + 1; } else { cafeCustomers.CustId = 1; } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.CafeCustomers.Add(cafeCustomers); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (CafeCustomersExists(cafeCustomers.CustId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetCafeCustomers", new { id = cafeCustomers.CustId }, cafeCustomers)); }