private List <Order> GetSatistics(DateTime startDate, DateTime endDate) { using (KursachDBContext context = new KursachDBContext()) { return(context.Orders.Where(o => o.OrderDate >= startDate && o.OrderDate <= endDate).ToList()); } }
public void CreateOrder(object parameter) { using (var context = new KursachDBContext()) { Order lastOrder = context.Orders.OrderByDescending(o => o.Id).FirstOrDefault(); int newId = 1; if (lastOrder != null) { newId = lastOrder.Id + 1; } Order newOrder = new Order() { Id = newId, Discount = Cost > 30 ? 10 : 0, IsCompleted = false, IsGiven = false, OrderDate = DateTime.Now }; if (Cost > 50 && Cost < 100) { newOrder.Discount = 5; } context.Orders.Add(newOrder); foreach (var product in OrderProducts) { ProductsOrder currEntity = context.ProductsOrders.Create(); currEntity.OrderId = newOrder.Id; currEntity.ProductId = product.Id; context.ProductsOrders.Add(currEntity); } context.SaveChanges(); WorkerWindowViewModel.Instance.UpdateView(); OrderWindowViewModel.Instance.UpdateOrder(); CashRepairWindow wnd = new CashRepairWindow(); try { wnd.ShowDialog(); } catch { } finally { OrderProducts = new ObservableCollection <Product>(); OnProperyChanged(nameof(OrderProducts)); } } }
public void AddProductToOrder(object parameter) { if (!(parameter is int)) { return; } using (var context = new KursachDBContext()) { int id = Convert.ToInt32(parameter); Product currProduct = context.Products.FirstOrDefault(p => p.Id == id); if (currProduct == null) { return; } OrderProducts.Add(currProduct); OnProperyChanged("OrderProducts"); } }
private void Auth(object param) { object[] prms = param as object[]; PasswordBox passwordBox = prms[0] as PasswordBox; string passwd = passwordBox.Password; Window wnd = prms[1] as Window; string str = Login + ":" + passwd; string hash = MD5.Create(str); // "d2abaa37a7c3db1137d385e1d8c15fd2" using (var context = new KursachDBContext()) { bool isExists = context.Users.FirstOrDefault(u => u.Hash.Equals(hash)) != null; if (isExists) { wnd.DialogResult = true; } else { MessageBox.Show("User does not exists."); } } }
public WorkerWindowViewModel() { context = new KursachDBContext(); Instance = this; }