public async static Task <List <CodigosDat> > GetCodigosDatsXtalla(string porder, string estilo, string usuario) { try { using (var contex = new AuditoriaEntities()) { var tarea1 = await Task.Run(() => { using (var contex1 = new AuditoriaEntities()) { var l1 = contex1.spdExtraeTallasXCortecompleto(0, porder, 0, estilo, usuario) .Select(x => new CodigosDat { Id_Order = 0, //idorder, POrder = porder, Size = x.Size, Quantity = x.Cantidad, Estado = "Generado", }).ToList(); return(l1); } }).ConfigureAwait(false); var listaTotal = new List <CodigosDat>(); int incrementable = 1; string corteCadenaProto = "9999999999"; foreach (var item in tarea1) { var subcadena = string.Concat(corteCadenaProto.Substring(0, 10 - item.POrder.ToString().Trim().Length)); listaTotal.Add(new CodigosDat() { // Id_Order = item.Id_Order, POrder = item.POrder, Size = item.Size.Replace('*', 'X'), NSeq = incrementable, Cantidad = item.Quantity, Resto = item.Quantity, codigoBarra = string.Concat(subcadena, item.POrder, string.Format("{0:000000}", incrementable)), Estado = item.Estado }); incrementable++; } return(listaTotal.OrderBy(x => x.NSeq).ToList()); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
public async static Task <List <CodigosDat> > GetCodigosDatsXtalla(int idorder, string porder, int?idestilo, string estilo, string usuario) { try { using (var contex = new AuditoriaEntities()) { var tarea1 = Task.Run(() => { using (var contex1 = new AuditoriaEntities()) { var l1 = contex1.spdExtraeTallasXCortecompleto(idorder, porder, idestilo, estilo, usuario) .Select(x => new CodigosDat { Id_Order = 0, //idorder, POrder = porder, Size = x.Size, Quantity = x.Cantidad, Estado = "Generado", }).ToList(); return(l1); } }); var tarea2 = Task.Run(() => { using (var contex1 = new AuditoriaEntities()) { var l2 = contex1.POrder.Join(contex1.tbBultosCodigosBarra, x => x.Id_Order, y => y.idCorte, (x, y) => new { x, y }) .Where(x => x.x.Id_Order == idorder) .Select( x => new CodigosDat { Id_Order = x.x.Id_Order, POrder = x.x.POrder1, Size = x.y.talla, NSeq = x.y.secuenciaUnidades, Cantidad = x.y.Cantidad, Resto = x.y.Restante, codigoBarra = x.y.codigoBarra, Estado = x.y.estado }).OrderBy(x => x.NSeq).ToList(); return(l2); } }); await Task.WhenAll(tarea1, tarea2).ConfigureAwait(false); var list = tarea1.Result; var listas = tarea2.Result; var listaTotal = new List <CodigosDat>(); int incrementable = 1; foreach (var item in list) { listaTotal.Add(new CodigosDat() { Id_Order = item.Id_Order, POrder = item.POrder, Size = item.Size.Replace('*', 'X'), NSeq = incrementable, Cantidad = item.Quantity, Resto = item.Quantity, codigoBarra = string.Concat(item.Id_Order.ToString(), incrementable.ToString(), item.Size.Replace('*', 'X')), Estado = item.Estado }); incrementable++; } return(listas.Count == 0 ? listaTotal.OrderBy(x => x.NSeq).ToList() : listas); } } catch (Exception) { return(null); } }