public ActionResult View(int id)
        {
            var orderInDb = _context.Orders
                            .Include(o => o.Customer)
                            .Include(o => o.Employee)
                            .Include(o => o.ServiceAppliance)
                            .SingleOrDefault(o => o.Id == id);

            if (orderInDb == null)
            {
                return(HttpNotFound());
            }

            var serviceCenter = _context.ServiceCenters
                                .Include(c => c.City)
                                .SingleOrDefault(c => c.Id == orderInDb.Employee.ServiceCenterId);

            var viewModel = new OrderViewViewModel
            {
                Order         = orderInDb,
                ServiceCenter = serviceCenter,
                ServiceTypes  = _context.ServiceTypes.ToList()
            };

            return(View(viewModel));
        }
예제 #2
0
        public ActionResult View(int id)
        {
            var model = new OrderViewViewModel();
            model.Order = _session.Get<Order>(id);

            return View(model);
        }
예제 #3
0
        public ActionResult View(int id)
        {
            var model = new OrderViewViewModel();

            model.Order = _session.Get <Order>(id);

            return(View(model));
        }
        public async Task <ActionResult> Create([Bind] OrderViewViewModel orderModel)
        {
            if (ModelState.IsValid)
            {
                // Unpack data from form and collect the necessary missing data
                Order order = new Order();
                order.CustomerId  = orderModel.CustomerID;
                order.CreatedDate = DateTime.Now;

                // Get the employee object attached to the logged in user
                var currentUser = User.Identity.GetUserId();
                var employee    = db.Employees.First(emp => emp.AspNetUserID == currentUser);
                order.SoldById = employee.EmployeeID;

                List <OrderProduct> orderProducts = new List <OrderProduct>();

                foreach (int productID in orderModel.ProductID)
                {
                    OrderProduct orderProduct = new OrderProduct();
                    orderProduct.OrderId   = -1;
                    orderProduct.ProductId = productID;

                    orderProducts.Add(orderProduct);
                }

                // Create the PackagedOrder, which will be sent through the Service Bus to the API
                PackagedOrder newOrder = new PackagedOrder();
                newOrder.Order         = order;
                newOrder.OrderProducts = orderProducts;

                // Handle timezone information. Client will send it in their local time. DateTimeZoneHandling.RoundtripKind maintains the timezone information in the DateTime
                // so it can be easily converted to the client's local time later on.
                JsonSerializerSettings jsonSettings = new JsonSerializerSettings()
                {
                    NullValueHandling    = NullValueHandling.Include,
                    DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind
                };

                // Serialize the PackagedOrder to JSON to send in the Service Bus
                string jsonOrder = JsonConvert.SerializeObject(newOrder, jsonSettings);

                // Create the message to be sent from the PackagedOrder
                var message = new BrokeredMessage(jsonOrder);

                // Asynchronously send the message to the Service Bus
                await QueueConnector.Client.SendAsync(message);

                return(RedirectToAction("Index"));
            }

            PopulateViewBag(orderModel.ProductID);

            return(View(orderModel));
        }