public ActionResult Create(int id) { using (CafeContext context = new CafeContext()) { ViewBag.LocationName = context.Locations.FirstOrDefault(loc => loc.LocationID == id).Name; } OrderViewModel o = new OrderViewModel { LocationID = id }; return View(o); }
public ActionResult Create(OrderViewModel order) { using (CafeContext context = new CafeContext()) { if (ModelState.IsValid) { TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); DateTime pacificTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz); if (order.PickUpAt.HasValue) { order.PickUpAt = TimeZoneInfo.ConvertTimeFromUtc(order.PickUpAt.Value.ToUniversalTime(), tz); } Order toAdd = new Order { LocationID = order.LocationID, PickUpAt = order.PickUpAt, CreatedAt = pacificTime, UserID = WebSecurity.GetUserId(User.Identity.Name) }; context.Orders.Add(toAdd); context.SaveChanges(); return RedirectToAction("Index"); } } return View(order); }
public OrderViewModel OrderToViewModel(Order order) { OrderViewModel ovm = new OrderViewModel() { CancelledAt = order.CancelledAt, CompletedAt = order.CompletedAt, CreatedAt = order.CreatedAt, LocationID = order.LocationID, OrderID = order.OrderID, PickUpAt = order.PickUpAt, StartedAt = order.StartedAt, UserID = order.UserID }; return ovm; }