public static Order Map(Data.Orders order, List <Pizza> pizzas) => new Order { LocationName = order.Location.LocationName, User = Map(order.User, order.User.Location.LocationName), Pizza = pizzas, TimeOfOrder = order.OrderTime };
public List <Orders> Orders_GetByAll() { List <Data.Orders> list = new List <Data.Orders>(); using (SqlCommand dbCmd = new SqlCommand("sp_Orders_GetByAll", GetConnection())) { Data.Orders obj = new Data.Orders(); dbCmd.CommandType = CommandType.StoredProcedure; SqlDataReader dr = dbCmd.ExecuteReader(); try { if (dr.HasRows) { while (dr.Read()) { list.Add(obj.OrdersIDataReader(dr)); } } } catch (Exception) { } finally { if (dr != null) { dr.Close(); } obj = null; } } return(list); }
public static Order Map(Data.Orders order) => new Order { OrderID = order.OrderId, UserID = order.UserId, OrderTime = order.OrderTime, Price = order.Price, StoreID = order.StoreId };
public static Order Map(Data.Orders otherOrder) => new Order { Id = otherOrder.Id, Timestamp = (DateTime)otherOrder.Timestamp, UserID = otherOrder.UserId, Store = otherOrder.LocationId, Price = (decimal)otherOrder.Price, Pizzas = otherOrder.OrderPizzaJunction.Select(j => Mapper.Map(j.Pizza)).ToList() };
public static Data.Orders Map(OrderW orderWeb, int locationId) { Data.Orders orderD = new Data.Orders { LocationId = locationId, NumberOfPizzas = orderWeb.Pizzas.Count, OrderTime = orderWeb.TimeOfOrder, UserId = orderWeb.User.Id }; return(orderD); }
public Orders OrdersIDataReader(IDataReader dr) { Data.Orders obj = new Data.Orders(); obj.Id = (dr["Id"] is DBNull) ? string.Empty : dr["Id"].ToString(); obj.OrderId = (dr["OrderId"] is DBNull) ? string.Empty : dr["OrderId"].ToString(); obj.Name = (dr["Name"] is DBNull) ? string.Empty : dr["Name"].ToString(); obj.Address = (dr["Address"] is DBNull) ? string.Empty : dr["Address"].ToString(); obj.Tel = (dr["Tel"] is DBNull) ? string.Empty : dr["Tel"].ToString(); obj.Email = (dr["Email"] is DBNull) ? string.Empty : dr["Email"].ToString(); obj.PaymentMethod = (dr["PaymentMethod"] is DBNull) ? string.Empty : dr["PaymentMethod"].ToString(); obj.Price = (dr["Price"] is DBNull) ? string.Empty : dr["Price"].ToString(); obj.Status = (dr["Status"] is DBNull) ? string.Empty : dr["Status"].ToString(); obj.OrderDate = (dr["OrderDate"] is DBNull) ? string.Empty : dr["OrderDate"].ToString(); obj.Detail = (dr["Detail"] is DBNull) ? string.Empty : dr["Detail"].ToString(); obj.DeliveryDate = (dr["DeliveryDate"] is DBNull) ? string.Empty : dr["DeliveryDate"].ToString(); return(obj); }
public ActionResult NewOrder(OrderW webOrder, IFormCollection collection) { TimeSpan timeSpan; // get all of the data from TempData and collection var location = collection["Location"]; var orderName = TempData.Get <String>("orderName"); var orderWeb = TempData.Get <OrderW>(orderName); TempData.Put("orderName", orderName); TempData.Put(orderName, orderWeb); try { timeSpan = DateTime.Now.Subtract(Repo.GetLastOrderFromLocation(orderWeb.User.Id, location).OrderTime); } catch (Exception E) { TimeSpan time1 = TimeSpan.FromHours(1); TimeSpan ts = DateTime.Now.TimeOfDay; timeSpan = ts.Add(time1); } if (timeSpan.Hours >= 2) { // Place the orderName and Order in the TempData in case the order cannnot be completed TempData.Put("orderName", orderName); TempData.Put(orderName, orderWeb); // Get the location from the db var locationOrder = Repo.GetLocation(location); // And make a LocationW object to check if there are enough ingridients LocationW LocationW = new LocationW { Id = locationOrder.Id, LocationName = locationOrder.LocationName, DoughQ = locationOrder.DoughQ, SouceQ = locationOrder.SouceQ, CheeseQ = locationOrder.CheeseQ, PepperoniQ = locationOrder.PepperoniQ }; // get all the pizzaz in Data.Pizza for convenience List <Data.Pizza> pizzas = OrderW.Map(orderWeb.Pizzas); // Assign values to the location and time of the order orderWeb.LocationName = location; orderWeb.TimeOfOrder = DateTime.Now; // Get the id of the location int locationId = Repo.GetLocationId(location); // Make an Data.Orders object to insert into the db Data.Orders orderD = OrderW.Map(orderWeb, locationId); if (LocationW.EnoughIngridients(pizzas)) { // Substract ingridients from the location LocationW.SubstractIngridients(pizzas); // Update the location in the db Repo.UpdateLocation(LocationW.Map(LocationW)); // Add order to the db Repo.AddOrder(orderD); // save changes in the db Repo.Save(); // Get the id of the order int orderId = Repo.GetOrderId(orderD); // Get the id of all the pizzas in the order (create a new pizza entry in the db if it doesn't exist) List <int> pizzaIds = Repo.AddPizzas(pizzas); // Add data to the junction table foreach (var item in pizzaIds) { Repo.AddPizzaOrders(orderId, item); } // Save changes to the db Repo.Save(); // Get the price of the order decimal price = Library.Location.OrderPrice(pizzas); // Place the id and price in the orderWeb obj orderWeb.Id = orderId; orderWeb.Price = price; // Insert the data into TempData to get it in the OrderReview TempData.Put("orderName", orderName); TempData.Put(orderName, orderWeb); // Let the user review his Order return(RedirectToAction(nameof(OrderReview), new { id = orderWeb.User.Id })); } else { ModelState.AddModelError("", "Sorry but that location does not have enough ingridients to complete your order"); return(NewOrder(orderName)); //return RedirectToAction(nameof(NewOrder), new { newOrder = orderName }); } } else { ModelState.AddModelError("", $"Your last order from this locations was {timeSpan.Hours} : {timeSpan.Minutes} : {timeSpan.Seconds} ago." + $"Need to wait at least 2 hours to order from the same location"); return(NewOrder(orderName)); } }