private void _order() { if (String.IsNullOrWhiteSpace(Name) || String.IsNullOrWhiteSpace(Phone) || String.IsNullOrWhiteSpace(Street) || String.IsNullOrWhiteSpace(Block) || String.IsNullOrWhiteSpace(Apartment)) { MessageBox.Show("Заполните все нужные поля"); return; } if (Carts.Count == 0) { MessageBox.Show("Корзина пустая"); } BLL.CustomerModel customer = new BLL.CustomerModel() { Name = this.Name, Phone = this.Phone, Address = String.Join(" ", this.Street, this.Block, this.Apartment) }; List <BLL.PizzaDetailModel> carts = new List <BLL.PizzaDetailModel>(); foreach (var item in Carts) { BLL.DetailModel detail = new BLL.DetailModel() { Quantity = (int)item.SelectedQuant, Size_ID = item.SelectedSizeID }; db.AddNewDetail(ref detail); carts.Add(new BLL.PizzaDetailModel() { Pizza_ID = item.SelectedPizzaID, TotalPrice = item.TotalPricePizza, Detail_ID = detail.ID }); } if (db.AddNewOrder(ref customer, ref carts)) { MessageBox.Show("Успех!"); Customers.Add(new CustomerViewModel(customer.ID)); } else { MessageBox.Show("Не успех!"); } }
public void AddNewDetail(ref BLL.DetailModel detail) { List <DetailModel> details = new List <DetailModel>(GetAllDetails()); foreach (var item in details) { if (item.Quantity == detail.Quantity && item.Size_ID == detail.Size_ID) { detail.ID = item.ID; return; } } Detail dt = new Detail() { Size_ID = detail.Size_ID, Quantity = detail.Quantity, }; db.Details.Create(dt); db.Save(); detail = new BLL.DetailModel(db.Details.GetLastRecord()); }