// GET: Customers public ActionResult Index(string sortBy) { ViewBag.NameSort = string.IsNullOrEmpty(sortBy) ? "Name desc" : ""; //get list of customers from db var customers = db.Customers.ToList(); // create list of customers from viewmodel var customersVM = new List <CustomerVM>(); foreach (var customer in customers) { customersVM.Add(CustomerVM.MapTo(customer)); } switch (sortBy) { case "Name desc": var clients = customersVM.OrderByDescending(x => x.Name); return(View(clients.ToList())); default: clients = customersVM.OrderBy(x => x.Name); return(View(clients.ToList())); } }
public ActionResult Edit([Bind(Include = "CustomerID,Name,SSN,Town")] CustomerVM customerVM) { if (ModelState.IsValid) { var customer = CustomerVM.MapTo(customerVM); db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customerVM)); }
public ActionResult Create([Bind(Include = "CustomerID,Name,SSN,Town")] CustomerVM customerVM) { if (ModelState.IsValid) { var customer = CustomerVM.MapTo(customerVM); db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customerVM)); }
public ActionResult Edit([Bind(Include = "CustomerID,FirstName,LastName,Phone")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } var customersVM = CustomerVM.MapTo(customer); return(View(customersVM)); }
// GET: Customers public ActionResult Index() { var customers = db.Customers.ToList(); var customersVM = new List <CustomerVM>(); foreach (var customer in customers) { customersVM.Add(CustomerVM.MapTo(customer)); } return(View(customersVM)); }
// GET: Customers/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Customer customer = db.Customers.Find(id); if (customer == null) { return(HttpNotFound()); } var customerVM = CustomerVM.MapTo(customer); return(View(customerVM)); }
public ActionResult IndexBook(string sortBy, string search) { ViewBag.StartDateSort = string.IsNullOrEmpty(sortBy) ? "StartDate desc" : ""; //get list of reservations from db var reservations = db.Reservations.Include(r => r.Car).Include(r => r.Customer).ToList(); var SSNSearchVM = new List <ReservationVM>(); // create list of reservations from viewmodel var reservationsVM = new List <ReservationVM>(); foreach (var reservation in reservations) { reservationsVM.Add(ReservationVM.MapTo(reservation)); } //adding Car Make and Customer Name in Reservation Index foreach (var reservationVM in reservationsVM) { reservationVM.Car = CarVM.MapTo(db.Cars.Find(reservationVM.CarID)); reservationVM.Customer = CustomerVM.MapTo(db.Customers.Find(reservationVM.CustomerID)); } if (search == null) { switch (sortBy) { case "StartDate desc": var bookings = reservationsVM.OrderByDescending(x => x.StartDate); return(View(bookings.ToList())); default: bookings = reservationsVM.OrderBy(x => x.StartDate); return(View(bookings.ToList())); } } else { SSNSearchVM = reservationsVM.Where(x => x.Customer.SSN == search).ToList <ReservationVM>(); return(View(SSNSearchVM)); } }
// GET: Reservations/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Reservation reservation = db.Reservations.Find(id); if (reservation == null) { return(HttpNotFound()); } var reservationVM = ReservationVM.MapTo(reservation); //adding Car Make and Customer Name in Reservation Details reservationVM.Car = CarVM.MapTo(db.Cars.Find(reservationVM.CarID)); reservationVM.Customer = CustomerVM.MapTo(db.Customers.Find(reservationVM.CustomerID)); return(View(reservationVM)); }
// GET: Reservations public ActionResult Index() { //get list of reservations from db var reservations = db.Reservations.Include(r => r.Car).Include(r => r.Customer).ToList(); // create list of reservations from viewmodel var reservationsVM = new List <ReservationVM>(); foreach (var reservation in reservations) { reservationsVM.Add(ReservationVM.MapTo(reservation)); } //adding Car Make and Customer Name in Reservation Index foreach (var reservationVM in reservationsVM) { reservationVM.Car = CarVM.MapTo(db.Cars.Find(reservationVM.CarID)); reservationVM.Customer = CustomerVM.MapTo(db.Customers.Find(reservationVM.CustomerID)); } return(View(reservationsVM)); }