private int Ventas(string codigo, string cuenta, int dias) { CredencialesEbay credencialesEbay = new CredencialesEbay(); int ArticuloID = 0; int i = credencialesEbay.Cuentas.IndexOf(cuenta); if (i < 0) { Debug.WriteLine("Funcion Ventas Codigo error IndexOf: " + codigo + " CUenta: " + cuenta); return(0); } cuenta = credencialesEbay.InicialesCuentas[i]; DateTime today = DateTime.Now; DateTime semana = today.AddDays(-1 * dias); try { MyEntityModel.ApplicationDbContextSql dbContextSql = new MyEntityModel.ApplicationDbContextSql(); ArticuloID = dbContextSql.Articulos.Where(w => w.Codigo == codigo).FirstOrDefault().ArticuloID; } catch (Exception e) { Console.WriteLine("B" + e.Message + " " + e.InnerException); } var SiEscandalloDbcontext = new MyEntityModel.ApplicationDbContextSql(); bool SiEscandallo = SiEscandalloDbcontext.SiTieneEscandallo(ArticuloID); int vendidos = 0; if (SiEscandallo == false) { try { MyEntityModel.ApplicationDbContextSql dbContextSql = new MyEntityModel.ApplicationDbContextSql(); vendidos = dbContextSql.Lineas.Where(w => w.ArticuloID == ArticuloID && w.Fecha >= semana && w.Historial.StartsWith(cuenta) && w.Unidades > 0).Sum(s => (int?)s.Unidades) ?? 0; } catch (Exception e) { Console.WriteLine("C " + e.Message + " " + e.InnerException); } return(vendidos); } // Si Escandallo == true else { try { MyEntityModel.ApplicationDbContextSql dbContextSql = new MyEntityModel.ApplicationDbContextSql(); vendidos = dbContextSql.Lineas.Where(w => w.ArticuloCompradoID == ArticuloID && w.Fecha >= semana && w.Historial.StartsWith(cuenta) && w.Unidades > 0).Sum(s => (int?)s.UnidadesArticuloComprado) ?? 0; } catch (Exception e) { Console.WriteLine("C " + e.Message + " " + e.InnerException); } return(vendidos); } }
public string LeerArticuloEbay(String ArticuloID, string cuenta, string articulo_mio, string codigo) { MyEntityModel.RepuestosDeMovilesDbContext dbContext = new MyEntityModel.RepuestosDeMovilesDbContext(); MyEntityModel.ApplicationDbContextSql dbContextSql = new MyEntityModel.ApplicationDbContextSql(); CredencialesEbay credencialeebay = new CredencialesEbay(); credencialeebay.cuenta = cuenta; ItemType Item; GetItemCall ap = new GetItemCall(credencialeebay.context); ap.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); ap.IncludeItemSpecifics = true; try { Item = ap.GetItem(ArticuloID); } catch (ApiException oApiEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Console.WriteLine("1 " + oApiEx.Message); return(oApiEx.Message); } catch (SdkException oSdkEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Console.WriteLine("2 " + oSdkEx.Message); return(oSdkEx.Message); } catch (Exception oEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Console.WriteLine("3 " + oEx.Message); return(oEx.Message); } EBAY_SEGUIMIENTO ebay_seguimiento = new EBAY_SEGUIMIENTO(); try { ebay_seguimiento = dbContext.EBAY_SEGUIMIENTO.Where(w => w.ARTICULO == Item.ItemID).FirstOrDefault(); } catch (Exception edb) { Console.WriteLine("Error en dbContext " + edb); } if (ebay_seguimiento != null) { ebay_seguimiento.Descripcion = Item.Description; ebay_seguimiento.DISPONIBLES = Item.Quantity - Item.SellingStatus.QuantitySold; ebay_seguimiento.ENVIO = (decimal?)Item.ShippingDetails.ShippingServiceOptions[0].ShippingServiceCost.Value; ebay_seguimiento.IMAGEN_EBAY = Item.PictureDetails.PictureURL[0]; ebay_seguimiento.PRECIO = (decimal?)Item.StartPrice.Value; ebay_seguimiento.SUBTITULO = Item.SubTitle; ebay_seguimiento.TITULO = Item.Title; ebay_seguimiento.VENDIDOS = Item.SellingStatus.QuantitySold; ebay_seguimiento.VENDIDOS_SEMANA = Ventas(ebay_seguimiento.ARTICULO_MIO, ebay_seguimiento.VENDEDOR, 7); ebay_seguimiento.VENDIDOS_MES = Ventas(ebay_seguimiento.ARTICULO_MIO, ebay_seguimiento.VENDEDOR, 30); ebay_seguimiento.FECHA = DateTime.Now; ebay_seguimiento.PictureURL = string.Join("\t", Item.PictureDetails.PictureURL.ToArray()); dbContext.SaveChanges(); return(""); } else { ebay_seguimiento = new EBAY_SEGUIMIENTO(); ebay_seguimiento.VENDEDOR = Item.Seller.UserID; ebay_seguimiento.ARTICULO = Item.ItemID; ebay_seguimiento.CODIGO = codigo; ebay_seguimiento.TITULO = Item.Title; ebay_seguimiento.SUBTITULO = Item.SubTitle; ebay_seguimiento.Descripcion = Item.Description; ebay_seguimiento.DISPONIBLES = Item.Quantity - Item.SellingStatus.QuantitySold; ebay_seguimiento.ENVIO = (decimal?)Item.ShippingDetails.ShippingServiceOptions[0].ShippingServiceCost.Value; ebay_seguimiento.IMAGEN_EBAY = Item.PictureDetails.PictureURL[0]; ebay_seguimiento.PRECIO = (decimal?)Item.StartPrice.Value; ebay_seguimiento.VENDIDOS = Item.SellingStatus.QuantitySold; ebay_seguimiento.VENDIDOS_SEMANA = Ventas(ebay_seguimiento.ARTICULO_MIO, ebay_seguimiento.VENDEDOR, 7); ebay_seguimiento.VENDIDOS_MES = Ventas(ebay_seguimiento.ARTICULO_MIO, ebay_seguimiento.VENDEDOR, 30); ebay_seguimiento.FECHA = DateTime.Now; ebay_seguimiento.PictureURL = string.Join("\t", Item.PictureDetails.PictureURL); dbContext.EBAY_SEGUIMIENTO.Add(ebay_seguimiento); dbContext.SaveChanges(); } return(""); }
public static ItemType LeerArticuloEbay(String ArticuloID, string cuenta) { new Thread(delegate() { fnNotificacion(" Leyendo " + ArticuloID); }).Start(); MyEntityModel.RepuestosDeMovilesDbContext dbContext = new MyEntityModel.RepuestosDeMovilesDbContext(); MyEntityModel.ApplicationDbContextSql dbContextSql = new MyEntityModel.ApplicationDbContextSql(); CredencialesEbay credencialeebay = new CredencialesEbay(); credencialeebay.cuenta = cuenta; ItemType Item; GetItemCall ap = new GetItemCall(credencialeebay.context); ap.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); ap.IncludeItemSpecifics = true; try { Notificacion(ArticuloID, 1); Item = ap.GetItem(ArticuloID); } catch (ApiException oApiEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Debug.WriteLine("1 " + oApiEx.Message); fnGrabarErrorEbayArticulo(ArticuloID, oApiEx.Message); return(null); } catch (SdkException oSdkEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Debug.WriteLine("2 " + oSdkEx.Message); fnGrabarErrorEbayArticulo(ArticuloID, oSdkEx.Message); return(null); } catch (Exception oEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Debug.WriteLine("3 " + oEx.Message); fnGrabarErrorEbayArticulo(ArticuloID, oEx.Message); return(null); } EBAY_SEGUIMIENTO ebay_seguimiento = new EBAY_SEGUIMIENTO(); try { ebay_seguimiento = dbContext.EBAY_SEGUIMIENTO.Where(w => w.ARTICULO == Item.ItemID).FirstOrDefault(); } catch (Exception edb) { Debug.WriteLine("Error en dbContext " + edb); } if (ebay_seguimiento != null) { Debug.WriteLine("Articulo " + ArticuloID + " Leido"); fnCopiarArticuloEbaySeguimiento(Item, ebay_seguimiento); try { dbContext.SaveChanges(); Debug.WriteLine("Articulo " + ArticuloID + " Grabado"); } catch { Debug.WriteLine("Articulo " + ArticuloID + " ****** ERROR AL GRABAR ******"); } } return(Item); }