public async Task <IActionResult> Create(Customer_ViewModel model) { var customer = new Customer(); customer.Email = model.Email; customer.FirstName = model.FirstName; customer.LastName = model.LastName; customer.Notes = model.Notes; customer.PhoneNumber = model.PhoneNumber; customer.EventId = model.EventId; customer.Age = model.Age; customer.GenderId = model.GenderId; TempData["notice"] = "Successfully registered"; if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); //perhaps there will be a conditional here later for roles where it loops back //to create if you are on the simple customer creator role, but otherwise goes //to the customers index return(RedirectToAction("Create", "Customers", new { eventId = customer.EventId })); //return RedirectToAction("Index", "Customers", new { eventId = customer.EventId }); //return RedirectToAction("Details", "Events", new { id = customer.EventId }); //return RedirectToAction(nameof(Index)); } return(View(customer)); }
// GET: Customers/Create public IActionResult Create(int eventId) { var model = new Customer_ViewModel(); model.EventId = eventId; model.HasItemsCheckedOut = false; var evnt = _context.Event.FirstOrDefault(e => e.Id == eventId); if (evnt != null) { model.EventName = evnt.Name; } var genders = _context.Gender.OrderBy(c => c.Name).Where(t => t.IsActive == true && t.Name != "Unisex").Select(x => new { Id = x.Id, Value = x.Name }); model.GenderList = new SelectList(genders, "Id", "Value"); return(View(model)); }
// GET: Customers/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var customer = await _context.Customer.SingleOrDefaultAsync(m => m.Id == id); if (customer == null) { return(NotFound()); } var model = new Customer_ViewModel(); model.Email = customer.Email; model.FirstName = customer.FirstName; model.LastName = customer.LastName; model.Notes = customer.Notes; model.PhoneNumber = customer.PhoneNumber; model.EventId = customer.EventId; model.HasItemsCheckedOut = false; model.Age = customer.Age; model.GenderId = customer.GenderId; var genders = _context.Gender.OrderBy(c => c.Name).Where(t => t.IsActive == true && t.Name != "Unisex").Select(x => new { Id = x.Id, Value = x.Name }); model.GenderList = new SelectList(genders, "Id", "Value"); var evnt = _context.Event.FirstOrDefault(e => e.Id == customer.EventId); if (evnt != null) { model.EventName = evnt.Name; } return(View(model)); }
public async Task <IActionResult> Edit(int id, Customer_ViewModel model) { if (id != model.Id) { return(NotFound()); } var customer = _context.Customer.FirstOrDefault(c => c.Id == id); customer.Email = model.Email; customer.FirstName = model.FirstName; customer.LastName = model.LastName; customer.Notes = model.Notes; customer.PhoneNumber = model.PhoneNumber; customer.EventId = model.EventId; customer.Age = model.Age; customer.GenderId = model.GenderId; if (ModelState.IsValid) { try { _context.Update(customer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(customer.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", "Customers", new { eventId = customer.EventId })); } return(View(model)); }