public void Create(OrderModel o) { // Order Order newOrder = new Order(); newOrder.UserId = _sa.GetUser(o.User.Email, o.User.Password).UserId; newOrder.StoreId = _sa.GetStore(o.StoreName).StoreId; // newOrder.StoreName = o.StoreName; newOrder.TotalCost = 0M; newOrder.OrderDate = DateTime.Now; // OrderPizza // Pizza foreach (var p in o.Pizzas) { Pizza newPizza = new Pizza(); newPizza.Cost = p.Cost; newPizza.SizeId = _sa.GetSize(p.Size).SizeId; newPizza.CrustId = _sa.GetCrust(p.Crust).CrustId; newPizza.Cost = _sa.GetSize(p.Size).Price + _sa.GetCrust(p.Crust).Price; foreach (var t in p.Toppings) { PizzaTopping pt = new PizzaTopping(); pt.Pizza = newPizza; pt.ToppingId = _sa.GetTopping(t).ToppingId; newPizza.PizzaTopping.Add(pt); newPizza.Cost += _sa.GetTopping(t).Price; } OrderPizza op = new OrderPizza(); op.Order = newOrder; op.Pizza = newPizza; newOrder.OrderPizza.Add(op); newOrder.TotalCost += newPizza.Cost; } _sa.CreateOrder(newOrder); }
public decimal GetSalesByMonth(StoreModel s, int m) { List <Order> orders = _sa.GetAllOrders(_sa.GetStore(s.StoreName).StoreId, m); decimal sum = 0M; foreach (var o in orders) { sum += o.TotalCost; } return(sum); }
public UserModel Read(string e, string p) { User u = _sa.GetUser(e, p); if (u == null) { return(null); } UserModel tempU = new UserModel(); tempU.FirstName = u.FirstName; tempU.LastName = u.LastName; tempU.Address.Street = u.Address.Street; tempU.Address.City = u.Address.City; tempU.Address.AddressState = u.Address.AddressState; tempU.Address.ZipCode = u.Address.ZipCode; tempU.Email = u.UserAccount.Email; tempU.Password = u.UserAccount.Password; if (u.UserType.UserType1 == "Manager") { tempU.Admin = true; return(tempU); } // get orders foreach (var o in u.Order) { Order currentOrder = _sa.GetOrder(o.OrderId); OrderModel newOrder = new OrderModel(); newOrder.StoreName = _sa.GetStore(currentOrder.StoreId).StoreName; newOrder.UserId = currentOrder.UserId; newOrder.StoreId = currentOrder.StoreId; newOrder.OrderDate = currentOrder.OrderDate; newOrder.TotalCost = currentOrder.TotalCost; foreach (var pizza in currentOrder.OrderPizza) { Pizza currentPizza = _sa.GetPizza(pizza.PizzaId); PizzaModel newPizza = new PizzaModel(); newPizza.Cost = currentPizza.Cost; newPizza.Crust = currentPizza.Crust.CrustName; newPizza.Size = currentPizza.Size.SizeName; foreach (var topping in currentPizza.PizzaTopping) { Topping t = _sa.GetTopping(topping.ToppingId); newPizza.Toppings.Add(t.ToppingName); } newOrder.Pizzas.Add(newPizza); } tempU.Orders.Add(newOrder); } return(tempU); }
public StoreModel Read(string s) { // if (s == null) // { // return null; // } Store tempStore = _sa.GetStore(s); StoreModel currentStore = new StoreModel(); currentStore.StoreName = tempStore.StoreName; currentStore.Address.Street = tempStore.Address.Street; currentStore.Address.City = tempStore.Address.City; currentStore.Address.AddressState = tempStore.Address.AddressState; currentStore.Address.ZipCode = tempStore.Address.ZipCode; foreach (var o in tempStore.Order) { Order currentOrder = _sa.GetOrder(o.OrderId); OrderModel newOrder = new OrderModel(); newOrder.UserId = currentOrder.UserId; newOrder.StoreId = currentOrder.StoreId; newOrder.OrderDate = currentOrder.OrderDate; newOrder.TotalCost = currentOrder.OrderPizza.Count; foreach (var pizza in currentOrder.OrderPizza) { Pizza currentPizza = _sa.GetPizza(pizza.PizzaId); PizzaModel newPizza = new PizzaModel(); newPizza.Cost = currentPizza.Cost; newPizza.Crust = currentPizza.Crust.CrustName; newPizza.Size = currentPizza.Size.SizeName; foreach (var topping in currentPizza.PizzaTopping) { Topping t = _sa.GetTopping(topping.ToppingId); newPizza.Toppings.Add(t.ToppingName); } newOrder.Pizzas.Add(newPizza); } // newOrder.Store = currentStore.Orders.Add(newOrder); // tempU.Orders.Add(newOrder); } // return _storeList.Find(x => x.Name == s.Name); return(currentStore); }