public ActionResult Create(BookingsModel model, string save_booking, string save_item)
        {
            //Create the booking or add a package
            SetupBookingsModel(model);
            IList<BookingItemModel> currentItems = new List<BookingItemModel>();
            if (HttpContext.Session["BookingItemModel"] != null)
            {
                currentItems = (List<BookingItemModel>)HttpContext.Session["BookingItemModel"];
            }

            if (model.Category != Guid.Empty)
            {
                model.LubeItems = GetItemsList(model.Category)
                    .Select(p => new SelectListItem() { Text = p.WebName, Value = p.Id.ToString() });
            }

            if (model.LubeItem != Guid.Empty)
            {
                model.Packages = GetPackageList(model.LubeItem)
                    .Select(p => new SelectListItem() { Text = p.Name, Value = p.Id.ToString() });
            }

            if (model.Package != Guid.Empty)
            {
                model.Units = GetUnits(model.Package)
                    .Select(p => new SelectListItem() { Text = p, Value = p });
            }

            if (save_item != null)
            {
                //Add item to model
                BookingItemModel bookingItem = new BookingItemModel();
                bookingItem.Category = model.Categories
                     .Where(p => p.Value == model.Category.ToString())
                    .Select(p => p.Text).FirstOrDefault();
                bookingItem.LubeItemId = model.LubeItem;
                bookingItem.LubeItem = model.LubeItems
                    .Where(p => p.Value == model.LubeItem.ToString())
                    .Select(p => p.Text).FirstOrDefault();
                bookingItem.PackageId = model.Package;
                bookingItem.Package = model.Packages
                    .Where(p => p.Value == model.Package.ToString())
                    .Select(p => p.Text).FirstOrDefault();
                bookingItem.Quantity = model.Quantity;
                bookingItem.Unit = model.Unit;
                currentItems.Add(bookingItem);
                model.BookingItems = currentItems;
                HttpContext.Session["BookingItemModel"] = currentItems;
                return View(model);
            }
            else if (save_booking != null)
            {
                //SAVE BOOKING TO DB
                if (HttpContext.Session["BookingItemModel"] == null)
                {
                    ModelState.AddModelError("ItemCount", "Please add at least one item to the booking.");
                    return View(model);
                }
                if (HttpContext.Session["BookingItemModel"] != null)
                {
                    if (currentItems.Count == 0)
                    {
                        ModelState.AddModelError("ItemCount", "Please add at least one item to the booking.");
                        return View(model);
                    }
                }
                model.BookingItems = currentItems;
                CreateBooking(model);
                HttpContext.Session.Remove("BookingItemModel");
                return RedirectToAction("Index");
            }
            return View(model);
        }
        private void SetupBookingsModel(BookingsModel model)
        {
            CategoryRespository categoryRepository = new CategoryRespository(_sqlConnectionString);
            model.Categories = categoryRepository.GetList()
                .Select(p => new SelectListItem() { Text = p.Name, Value = p.Id.ToString() });
            IEnumerable<SelectListItem> tempList = new List<SelectListItem>();
            //{
            //   new SelectListItem()
            //   {
            //       Text = "TEST",
            //       Value = Guid.NewGuid().ToString()
            //   },
            //   new SelectListItem()
            //   {
            //       Text = "TEST2",
            //       Value = Guid.NewGuid().ToString()
            //   }
            //};
            model.LubeItems = tempList;
            model.Packages = tempList;
            model.Units = tempList;

            model.BookingItems = new List<BookingItemModel>();
        }
 private void CreateBooking(BookingsModel model)
 {
     BookingRepository bookingRepo = new BookingRepository(_sqlConnectionString);
     Booking booking = new Booking();
     booking.Dealer = new Dealer();
     booking.Dealer.Id = _userInfo.Id;
     booking.Dealer.Name = _userInfo.DealerName;
     IList<BookingItem> items = new List<BookingItem>();
     foreach (BookingItemModel modelItem in model.BookingItems)
     {
         BookingItem bookingItem = new BookingItem();
         bookingItem.Item = new Item()
         {
             Id = modelItem.LubeItemId
         };
         bookingItem.Package = new Package()
         {
             Id = modelItem.PackageId
         };
         bookingItem.Quantity = modelItem.Quantity;
         bookingItem.Unit = modelItem.Unit;
         items.Add(bookingItem);
     }
     booking.Items = items;
     booking.InvoiceDate = model.InvoiceDate;
     bookingRepo.Create(booking);
 }
 public ActionResult Create()
 {
     BookingsModel model = new BookingsModel();
     SetupBookingsModel(model);
     return View(model);
 }
 public ActionResult Edit(string something)
 {
     BookingsModel model = new BookingsModel();
     model.Categories = new List<SelectListItem>();
     model.LubeItems = new List<SelectListItem>();
     model.Packages = new List<SelectListItem>();
     model.Units = new List<SelectListItem>();
     return View(model);
 }