예제 #1
0
        public MenuViewModel()
        {
            Headers = new List<Header>();
            if (IsInDesignMode)
            {
                var header = new Header {Title = "Header"};
                var meal = new Meal {Title = "Meal"};
                header.Meals.Add(meal);
                Headers.Add(header);
                Meals = new List<Meal>(header.Meals);
                Header = header;
            }
            else
            {
                using (var entities = new HillStationEntities())
                {
                    foreach (var header in entities.Headers.Include(h => h.Meals).OrderBy(h => h.DisplayOrder).ToList())
                    {
                        Headers.Add(new Header(header));
                    }
                }
            }

            Cancel = new RelayCommand(CancelUpdate);
            SaveData = new RelayCommand(Save);
            Decrement = new RelayCommand<string>(p => AdjustPrice(p, -0.05m));
            Increment = new RelayCommand<string>(p => AdjustPrice(p, 0.05m));
        }
예제 #2
0
 public void RemoveCustomer(Customer customer)
 {
     using (var entities = new HillStationEntities())
     {
         var customerEntity = entities.Customers.Find(customer.Id);
         entities.Customers.Remove(customerEntity);
         entities.SaveChanges();
     }
 }
예제 #3
0
 public Customer AddCustomer(Customer customer)
 {
     using (var entities = new HillStationEntities())
     {
         entities.Customers.Add(customer);
         entities.SaveChanges();
         entities.Entry(customer).Reload();
         return customer;
     }
 }
예제 #4
0
 public void UpdateCustomer(Customer customer)
 {
     using (var entities = new HillStationEntities())
     {
         var customerEntity = entities.Customers.Find(customer.Id);
         customerEntity.Name = customer.Name;
         customerEntity.Address = customer.Address;
         customerEntity.Postcode = customer.Postcode;
         customerEntity.Phone = customer.Phone;
         entities.SaveChanges();
     }
 }
예제 #5
0
 private void Save()
 {
     using (var entities = new HillStationEntities())
     {
         foreach (var header in Headers)
         {
             entities.Headers.Attach(header);
             entities.Entry(header).State = EntityState.Modified;
             foreach (var meal in header.Meals)
             {
                 entities.Meals.Attach(meal);
                 entities.Entry(meal).State = EntityState.Modified;
             }
         }
         entities.SaveChanges();
         OnMenuOpdated(new MenuUpdatedEventArgs {UpdateOperation = UpdateOperation.Updated});
     }
 }
예제 #6
0
 private Task<bool> Initialise()
 {
     return Task.Factory.StartNew(() =>
     {
         using (var entities = new HillStationEntities())
         {
             Headers =
                 new List<Header>(
                     entities.Headers.OrderBy(h => h.DisplayOrder).ToList().Select(header => new Header(header)));
             Customers = new List<Customer>(entities.Customers.OrderBy(c => c.Name));
         }
         return true;
     });
 }