コード例 #1
0
        public HttpResponseMessage ConfirmProductDetails(ProductIdArgs args, bool confirm, HttpRequestMessage request)
        {
            DynamoDBTracer.Tracer.Write(string.Format("ConfirmProductDetails called. Args: {0}", args), "Verbose");
            this.CheckAndUpdateDoSLimits(request, args.EmailId);
            HttpResponseMessage response;

            try
            {
                var catalogProvider = PriceUpdateContext.Instance.CatalogFactory.GetProductCatalogProvider();
                ProductCatalogEntity catalogEntity = catalogProvider.GetProduct(args);
                if (string.IsNullOrEmpty(catalogEntity.EmailId) || string.IsNullOrEmpty(catalogEntity.ASIN))
                {
                    response = new HttpResponseMessage(HttpStatusCode.NotFound);
                    return(response);
                }
                catalogEntity.IsConfirmed = confirm;
                catalogProvider.UpdateProduct(catalogEntity);
                response = new HttpResponseMessage(HttpStatusCode.OK);
            }
            catch
            {
                response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
            }
            DynamoDBTracer.Tracer.Write(string.Format("ConfirmProductDetails succeeded. Args: {0}", args), "Verbose");
            return(response);
        }
コード例 #2
0
        public GetProductAPIContract UpdateProductDetails(UpdateProductAPIArgs args, HttpRequestMessage request, string baseRequestUri)
        {
            DynamoDBTracer.Tracer.Write(string.Format("UpdateProductDetails called. Args: {0}", args), "Verbose");
            this.CheckAndUpdateDoSLimits(request, args.EmailId);
            ProductCatalogEntity catalogEntity = ValidateAndGetEntityFromArgs(args);
            var    offers        = AmazonProductHelper.GetOffers(args.ProductASIN, args.ProductRegion.ToString());
            var    offersSummary = offers.Items.FirstOrDefault().Item.FirstOrDefault().OfferSummary;
            string price         = offersSummary.LowestNewPrice.Amount;

            catalogEntity.InitialPrice = (double.Parse(price) / 100).ToString();
            catalogEntity.CurrencyCode = offersSummary.LowestNewPrice.CurrencyCode;

            var catalogProvider = PriceUpdateContext.Instance.CatalogFactory.GetProductCatalogProvider();

            catalogProvider.UpdateProduct(catalogEntity);

            DynamoDBTracer.Tracer.Write(string.Format("Catalog update succeeded. Args: {0}", args), "Verbose");

            GetProductAPIArgs getArgs = new GetProductAPIArgs
            {
                ProductASIN   = args.ProductASIN,
                ProductRegion = args.ProductRegion,
            };

            var productDetails = this.GetProductDetails(getArgs, request);

            productDetails.CurrentPrice = catalogEntity.InitialPrice;
            productDetails.CurrencyCode = catalogEntity.CurrencyCode;
            productDetails.AmazonUrl    = AmazonProductAPIWrapper.AmazonProductAPIConstants.RegionMapping[args.ProductRegion];
            productDetails.EmailId      = catalogEntity.EmailId;

            return(productDetails);
            //Start a background task to send confirmation email
            //Task.Factory.StartNew(() => SendConfirmationMail(args, baseRequestUri), TaskCreationOptions.None);
        }
コード例 #3
0
        private static ProductCatalogEntity ValidateAndGetEntityFromArgs(UpdateProductAPIArgs args)
        {
            ProductCatalogEntity catalogEntity = new ProductCatalogEntity
            {
                ASIN             = args.ProductASIN,
                Country          = args.ProductRegion.ToString(),
                EmailId          = args.EmailId,
                ToEmailEveryWeek = args.ToEmailEveryWeek,
                ToEmailOnDate    = args.ToEmailOnDate,
                ToEmailOnPrice   = args.ToEmailOnPrice,
                IsConfirmed      = false,
                IsDeleted        = false,
                ProductPriceType = args.ProductPriceType,
                DateLastUpdated  = DateTime.UtcNow.Date,
            };

            if (catalogEntity.ToEmailEveryWeek)
            {
                if (Enum.IsDefined(typeof(DayOfWeek), args.DayToEmail) && args.EmailEveryWeekDuration != null)
                {
                    catalogEntity.DayToEmail             = args.DayToEmail;
                    catalogEntity.EmailEveryWeekDuration = args.EmailEveryWeekDuration;
                }
                else
                {
                    throw new ArgumentException("Day of week is not a valid day or the duration is invalid");
                }
            }

            if (catalogEntity.ToEmailOnDate)
            {
                if (args.DateToEmail != null)
                {
                    catalogEntity.DateToEmail = args.DateToEmail;
                }
                else
                {
                    throw new ArgumentException("The date to email is invalid");
                }
            }

            if (catalogEntity.ToEmailOnPrice)
            {
                double value;
                if (double.TryParse(args.PriceToEmail, out value) && args.EmailOnPriceDuration != null)
                {
                    catalogEntity.PriceToEmail         = args.PriceToEmail;
                    catalogEntity.EmailOnPriceDuration = args.EmailOnPriceDuration;
                }
                else
                {
                    throw new ArgumentException("Price is not a valid double or the duration is invalid");
                }
            }
            return(catalogEntity);
        }
コード例 #4
0
 public void UpdateProduct(ProductCatalogEntity entityToUpdate)
 {
     //Make version checks
     //Increment version
     this.dbContext.Save <ProductCatalogEntity>(entityToUpdate);
 }
コード例 #5
0
        private static void AddItemToEmail(Dictionary <string, List <ProductEmailDetails> > emailsToSend, ProductCatalogEntity product)
        {
            var                 itemDetail   = AmazonProductHelper.GetItemDetails(product.ASIN, product.Country);
            string              itemName     = itemDetail.Items.FirstOrDefault().Item.FirstOrDefault().ItemAttributes.Title;
            var                 cartDetail   = AmazonProductHelper.GetCartDetails(product.ASIN, product.Country);
            string              cartUrl      = cartDetail.Cart.FirstOrDefault().PurchaseURL;
            const string        htmlATag     = @"<a href={0}>Click here to buy!</a>";
            ProductEmailDetails emailDetails = new ProductEmailDetails
            {
                ProductName         = itemName,
                CurrentPrice        = product.CurrentPrice,
                InitialPrice        = product.InitialPrice,
                ProductPurchaseLink = string.Format(htmlATag, cartUrl)
            };

            if (!emailsToSend.ContainsKey(product.EmailId))
            {
                emailsToSend.Add(product.EmailId, new List <ProductEmailDetails> {
                    emailDetails
                });
            }
            else
            {
                emailsToSend[product.EmailId].Add(emailDetails);
            }
        }