Exemple #1
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);
        }
Exemple #2
0
 private void SendConfirmationMail(UpdateProductAPIArgs args, string baseRequestUri)
 {
     string confirmRequestFormat = "{0}?EmailId={1}&ASIN={2}&confirmed=true";
     string requestUri           = string.Format(confirmRequestFormat, baseRequestUri.TrimEnd('/'), args.EmailId, args.ProductASIN);
     string mailContent          = WebAPIHelper.GetConfirmationMail(requestUri);
     //EmailManagerContext.Instance.SendHtmlEmail(args.EmailId, "Confirmation mail", mailContent);
 }
Exemple #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);
        }