Esempio n. 1
0
        public ActionResult Save(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(View("CustomerForm"));
            }

            if (customer.Id == 0)
            {
                customer.MovieLibrary = new List <Movie>();
                CustomersMockData.AddCustomer(customer);
            }
            else
            {
                var customerInDb    = CustomersMockData.GetCustomers().Single(c => c.Id == customer.Id);
                int indexOfCustomer = CustomersMockData.CustomerCollection.IndexOf(customerInDb);

                customerInDb.Name = customer.Name;
                customerInDb.IsSubcribedToNewsletter = customer.IsSubcribedToNewsletter;
                customerInDb.Birthdate = customer.Birthdate;

                CustomersMockData.CustomerCollection[indexOfCustomer] = customerInDb;
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public ActionResult Details(int id)
        {
            var selectedCustomer = CustomersMockData.GetCustomers().FirstOrDefault(c => c.Id == id);

            if (selectedCustomer != null)
            {
                return(View("Details", selectedCustomer));
            }
            else
            {
                return(HttpNotFound());
            }
        }
 // GET /api/customers
 public IEnumerable <Customer> GetCustomers()
 {
     return(CustomersMockData.GetCustomers());
 }