public async Task <IActionResult> SetShipment(OrderVModel item) { MonitorVModel mntr = new MonitorVModel(); if (item.OrderID > 0) { //Se pone el embarque activo OrderEModel order = _context.Order.FirstOrDefault(x => x.OrderID == item.OrderID); order.OnShipment = true; order.ReaderID = item.ReaderID; var succes = await _contextOrder.UpdateItemAsync(order); //Obtengo el nombre de reader asignado ReaderEModel reader = _context.Reader.FirstOrDefault(x => x.ReaderID == item.ReaderID); mntr.Portal = reader.Name; mntr.IdOrden = order.OrderID; mntr.Embarque = order.ShipmentNumber; mntr.IdPortal = (int)order.ReaderID; return(RedirectToAction("Monitor", mntr));//Monitor = mntr } else { ViewBag.Show = false; } return(null); }
public static int IniciarEmbarque(string embarque, int anden) { OrderEModel orden = new OrderEModel(); int uno = 0; using (var unitOfWork = new UnitOfWork(new ApplicationDbContext())) { var ordenOld = unitOfWork.OrderR.ReadsItems(x => x.ShipmentNumber == embarque).FirstOrDefault(); ordenOld.ReaderID = anden; ordenOld.OnShipment = true; uno = unitOfWork.Complete(); // orden = await unitOfWork.OrderR.UpdateItemAsync(ordenOld); } return(uno); }
public IActionResult Index(OrderVModel item) { if (ModelState.IsValid) { #region Fill select ViewBag.ReaderList = new SelectList(_context.Reader.ToList(), "ReaderID", "Name"); #endregion #region Get order by ID OrderEModel orderModel = new OrderEModel(); orderModel = _context.Order.FirstOrDefault(x => x.ShipmentNumber == item.Number); if (null == orderModel) { //Actualizar Orden orderModel = new OrderEModel() { Date = DateTime.Now, Number = item.Number, OnShipment = false, ReaderID = null, ShipmentNumber = item.Number }; orderModel = _context.Order.Add(orderModel).Entity; } //else //{ // orderModel = new OrderEModel() // { // ID = order.ID, // Date = order.Date, // Number = order.Number, // OnShipment = order.OnShipment, // ReaderID = order.ReaderID, // ShipmentNumber = order.Number // }; //} #endregion #region obtener información de embarques //1.- Obtener el total de piezas List <OrderDetailVModel> embarques = new List <OrderDetailVModel> { new OrderDetailVModel { Traza = 100922, PartNumber = "A2C98063402", Quantity = 48 }, new OrderDetailVModel { Traza = 100920, PartNumber = "A2C98062602", Quantity = 240 }, new OrderDetailVModel { Traza = 100921, PartNumber = "A2C98062602", Quantity = 96 }, new OrderDetailVModel { Traza = 100921, PartNumber = "A2C98062702", Quantity = 48 }, }; // 1.1.-el total de piezas convertirlo a tarimas foreach (OrderDetailVModel embarque in embarques) { Console.WriteLine(embarque.PartNumber); embarque.UnitID = embarque.Quantity / 48; embarque.OrderID = orderModel.OrderID; } List <OrderDetailEModel> ordersDetail = JsonConvert.DeserializeObject <List <OrderDetailEModel> >(JsonConvert.SerializeObject(embarques).ToString()); Console.WriteLine(embarques); _context.OrderDetail.AddRange(ordersDetail); _context.SaveChanges(); #endregion OrderVModel orders = JsonConvert.DeserializeObject <OrderVModel>(JsonConvert.SerializeObject(orderModel).ToString()); orders.ListOrderDetail = embarques; ViewBag.OrderDetail = embarques; ViewBag.Show = true; return(View(orderModel)); } else { ViewBag.Show = false; } return(View(item)); }
public async Task <IActionResult> Index(OrderVModel item) { OrderVModel orders = new OrderVModel(); OrderEModel orderModel = new OrderEModel(); try { if (ModelState.IsValid) { #region Fill select ViewBag.ReaderList = new SelectList(_context.Reader.ToList(), "ReaderID", "Name"); #endregion var exist = _contextOrder.GetOrderOnshipment(item.ShipmentNumber); if (exist == null) { #region obtener información de embarques //1.- Obtener el total de piezas ShipmentVModel result = test(item.ShipmentNumber); int index = 0; // 1.1.-Obtener de traza el total de piezas por tarima del número de parte foreach (OrderDetailVModel embarque in result.detalle) { Console.WriteLine(index); //TODO: Conectar con traza y mediante el numero de parte obtener el total de piezas por pallet int pallets = int.Parse(embarque.cantidad) / 48; embarque.OrderID = orderModel.OrderID; embarque.shipment = orderModel.ShipmentNumber; Console.WriteLine(embarque.continentalpartnumber); embarque.total_pallets = pallets; index++; } #endregion #region CreateShipment orders = await _contextOrder.CreateShipment(item, result.detalle); #endregion ViewBag.OrderDetail = orders.ListOrderDetail; ViewBag.Show = true; return(View(orders)); } else if (exist.OnShipment == true && exist.Finished == false && exist.ReaderID != null) { var mntr = GetInfoMonitor(exist.OrderID); mntr.IdOrden = exist.OrderID; mntr.IdPortal = (int)exist.ReaderID; mntr.Embarque = exist.ShipmentNumber; return(RedirectToAction("Monitor", mntr));//Monitor = mntr } else if (exist.Finished == true) { ViewBag.shipment = "Este embarque esta terminado"; ViewBag.Show = false; return(View()); } else { ViewBag.Show = true; orders = _contextOrder.GetQueryOrderComplete(exist.OrderID); ViewBag.OrderDetail = orders.ListOrderDetail; return(View(orders)); } } else { ViewBag.Show = false; } } catch (DataValidationException dex) { //TODO: Mostrar el mensaje en la pantala principal this.ModelState.AddModelError(dex.PropertyName, dex.ErrorMessage); } return(View()); }