Exemplo n.º 1
0
 private async Task SetOffers(List <Offer> offers)
 {
     foreach (Offer offer in offers)
     {
         OfferOrder offerOrder = null;
         PriceOffer priceOffer = null;
         try
         {
             if (!sqlCommandTools.CheckOffer(offer.id))
             {
                 offerOrder = new OfferOrder();
                 priceOffer = new PriceOffer();
                 priceOffer.DatateUpdate = DateTime.Now.ToString();
                 priceOffer.Price        = offer.price;
                 offerOrder.Id           = offer.id;
                 offerOrder.Description  = offer.description;
                 offerOrder.Id_category  = offer.id_category;
                 offerOrder.Name         = offer.name;
                 offerOrder.Store_id     = offer.store_id;
                 offerOrder.PriceOffers  = new List <PriceOffer>();
                 offerOrder.PriceOffers.Add(priceOffer);
                 sqlCommandTools.AddOffer(offerOrder);
             }
         }
         catch (Exception e)
         {
             File.AppendAllText("log/SetOffers.txt", $"{e.Message} {Environment.NewLine}");
         }
     }
 }
Exemplo n.º 2
0
        public async void AddPrice(string idOffer, PriceOffer priceOffer)
        {
            OfferOrder offerOrder = context.OfferOrders.Include(o => o.PriceOffers).First(o => o.Id == idOffer);

            if (offerOrder.PriceOffers == null)
            {
                offerOrder.PriceOffers = new List <PriceOffer>();
            }
            offerOrder.PriceOffers.Add(priceOffer);
            await context.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public bool CheckPrice(string idOffer)
        {
            bool isDataUpdate = false;

            using (var c = new Context())
            {
                OfferOrder offerOrder = c.OfferOrders.Include(o => o.PriceOffers).First(o => o.Id == idOffer);
                if (offerOrder.PriceOffers != null && offerOrder.PriceOffers.Count != 0)
                {
                    string   priceOfferDatateUpdate = offerOrder.PriceOffers.Last().DatateUpdate;
                    DateTime dateTime = DateTime.Parse($"{GetDFormat(priceOfferDatateUpdate.Remove(priceOfferDatateUpdate.IndexOf(" ")))} {priceOfferDatateUpdate.Remove(0, priceOfferDatateUpdate.IndexOf(" ") + 1)}");
                    if (dateTime < DateTime.Now.AddHours(-20))
                    {
                        isDataUpdate = true;
                    }
                }
            }
            return(isDataUpdate);
        }
Exemplo n.º 4
0
        private async Task <OfferOrder> GetOfferOrder(string idShiping)
        {
            OfferOrder offerOrder1 = null;

            if (sqlCommandTools.CheckOffer(idShiping))
            {
                offerOrder1 = sqlCommandTools.GetOfferOrder(idShiping);
            }
            else
            {
                OfferOrder offerOrder = new OfferOrder();
                PriceOffer priceOffer = new PriceOffer();
                priceOffer.DatateUpdate = DateTime.Now.ToString();
                offerOrder.Id           = idShiping;
                offerOrder.Store_id     = 0;
                offerOrder.Name         = "New";
                offerOrder.PriceOffers  = new List <PriceOffer>();
                offerOrder.PriceOffers.Add(priceOffer);
                sqlCommandTools.AddOffer(offerOrder);
            }
            return(offerOrder1);
        }
Exemplo n.º 5
0
        public async Task <Response> GetStatistics(string idShiping)
        {
            Store         store         = null;
            ResponseOrder responseOrder = null;
            ResponseStore responseStore = null;
            Response      response      = new Response();
            OfferOrder    offerOrder1   = await GetOfferOrder(idShiping);

            if (offerOrder1.Store_id != 0)
            {
                store = await GetStore(offerOrder1.Store_id.ToString());
            }
            if (offerOrder1 != null)
            {
                responseOrder = new ResponseOrder();
                DateTime dateTime = DateTime.Parse(offerOrder1.PriceOffers.First().DatateUpdate);
                if (dateTime.AddMonths(1) <= DateTime.Now)
                {
                    responseOrder.PriceOffers = offerOrder1.PriceOffers;
                    responseOrder.Status      = "OK";
                }
                else
                {
                    responseOrder.PriceOffers = new List <PriceOffer>();
                    responseOrder.Status      = "No_Content";
                }
            }
            else
            {
                responseOrder             = new ResponseOrder();
                responseOrder.PriceOffers = new List <PriceOffer>();
                responseOrder.Status      = "No_Content";
            }
            if (store != null)
            {
                responseStore = new ResponseStore();
                double timeOnTheMarketYears = 0;
                responseStore.CommunicationS       = Convert.ToInt32(store.Communication.Replace("%", ""));
                responseStore.ShippingSpeedS       = Convert.ToInt32(store.ShippingSpeed.Replace("%", ""));
                responseStore.ItemAsDescribedS     = Convert.ToInt32(store.ItemAsDescribed.Replace("%", ""));
                responseStore.StartOfSaleS         = GetPercentStartOfSale(store.StartOfSales, ref timeOnTheMarketYears);
                responseStore.FeedBackS            = GetPercentFeedBack(Convert.ToInt32(store.Positive4_5Stars.Replace(",", "").Trim()), Convert.ToInt32(store.Neutral3Stars.Replace(",", "").Trim()), Convert.ToInt32(store.Negative1_2Stars.Replace(",", "").Trim()));
                responseStore.Seller_RatingS       = GetPercentSeller_Rating(responseStore.CommunicationS + responseStore.ShippingSpeedS + responseStore.ItemAsDescribedS + responseStore.StartOfSaleS + responseStore.FeedBackS);
                responseStore.TimeOnTheMarketYears = timeOnTheMarketYears.ToString();
                responseStore.Communication        = GetDescCommunication(responseStore.CommunicationS);
                responseStore.ShippingSpeed        = GetShippingSpeed(responseStore.ShippingSpeedS);
                responseStore.ItemAsDescribed      = GetDescItemAsDescribed(responseStore.ItemAsDescribedS);
                responseStore.StartOfSale          = GetDescStartOfSale(timeOnTheMarketYears);
                responseStore.FeedBack             = GetDescFeedBack(responseStore.FeedBackS);
                responseStore.Seller_Rating        = GetDescSeller_Rating(responseStore.Seller_RatingS);
                responseStore.Status = "OK";
            }
            else
            {
                responseStore        = new ResponseStore();
                responseStore.Status = "No_Content";
            }
            response.ResponseOrder = responseOrder;
            response.ResponseStore = responseStore;
            return(response);
        }
Exemplo n.º 6
0
        internal string GetOneShiping(string idShiping)
        {
            OfferOrder offerOrder = sqlCommandTools.GetOfferOrder(idShiping.ToString());

            return(JsonConvert.SerializeObject(offerOrder));
        }
Exemplo n.º 7
0
 public void AddOffer(OfferOrder offerOrder)
 {
     context.OfferOrders.Add(offerOrder);
     context.SaveChanges();
 }
Exemplo n.º 8
0
 public async void UpdateShiping(OfferOrder offerOrder)
 {
     context.OfferOrders.Update(offerOrder);
     await context.SaveChangesAsync();
 }