Exemple #1
0
        // GET: Orders/Create
        public ActionResult Create()
        {
            var ViewModel = new OrderViewModel();

            ViewModel.Locations = LocRepo.GetAllLocations().ToList();
            ViewModel.Customers = CusRepo.GetCustomers().ToList();
            ViewModel.Products  = ProdRepo.GetAllProducts().Select(p => new ProductViewModel(p)).ToList();
            return(View(ViewModel));
        }
        // GET: Customer/Details/5
        public ActionResult Details(int id)
        {
            IEnumerable <Order> orders = CusRepo.GetOrderHistoryByCustomer(id);
            var ViewModels             = orders.Select(o => new OrderViewModel
            {
                OrderId    = o.OrderId,
                OrderTime  = o.OrderTime,
                LocationId = o.LocationId,
                CustomerId = o.CustomerId,
                OrderTotal = o.OrderTotal
            });

            return(View(ViewModels));
        }
        // GET: Customer
        public ActionResult Index()
        {
            IEnumerable <Library.Customer>  customerList = CusRepo.GetCustomers().ToList();
            IEnumerable <CustomerViewModel> viewModels   = customerList.Select(x => new CustomerViewModel
            {
                CustomerId        = x.CustId,
                FName             = x.FirstName,
                LName             = x.LastName,
                Phone             = x.PhoneNumber,
                DefaultLocationId = x.DefaultStoreId
            });

            return(View(viewModels));
        }
        public ActionResult Delete(int id, IFormCollection collection)
        {
            try
            {
                CusRepo.DeleteCustomer(id);
                CusRepo.Save();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
        //TODO: Add view for delete

        // GET: Customer/Delete/5
        public ActionResult Delete(int id)
        {
            Customer customer  = CusRepo.GetCustomerById(id);
            var      viewModel = new CustomerViewModel
            {
                CustomerId        = customer.CustId,
                FName             = customer.FirstName,
                LName             = customer.LastName,
                Phone             = customer.PhoneNumber,
                DefaultLocationId = customer.DefaultStoreId
            };

            return(View(viewModel));
        }
 public ActionResult Create(CustomerViewModel customer)
 {
     try
     {
         var newCustomer = new Customer
         {
             FirstName      = customer.FName,
             LastName       = customer.LName,
             PhoneNumber    = customer.Phone,
             DefaultStoreId = customer.DefaultLocationId
         };
         CusRepo.AddCustomer(newCustomer);
         CusRepo.Save();
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(RedirectToAction(nameof(Index)));
     }
 }