Esempio n. 1
0
        public async Task <IActionResult> GetPaymentPlan(int id)
        {
            var cat = await _paymentPlanService.GetPaymentPlanAsync(id);

            if (cat == null)
            {
                return(NotFound());
            }

            return(Ok(cat));
        }
Esempio n. 2
0
        public async Task <ProductResponseObject> AddProductAsync(ProductRequestObject product, HttpClient bucketClient)
        {
            //Get Associated Payment plans
            var productPlans = new List <ProductPaymentPlan>();

            foreach (int id in product.AssociatedPaymentPlans)
            {
                var plan = await _paymentPlanService.GetPaymentPlanAsync(id);

                if (plan == null)
                {
                    throw new Exception("No Active Associated Plan ");
                }
                productPlans.Add(new ProductPaymentPlan {
                    PaymentPlanName = plan.PlanName, ProductName = product.Name, PaymentPlanId = plan.Id
                });
            }

            //add cover image
            S3AddFileResponse coverImageObj = (await AddImageToS3Bucket(product.CoverImage, bucketClient))[0];
            var productImages = new List <ProductImage>()
            {
                new ProductImage {
                    ImageUrl     = coverImageObj?.ActualObjectUrl ?? "cover",
                    IsCoverImage = true,
                }
            };

            //add other images
            foreach (var image in product.AlternateProductImages)
            {
                S3AddFileResponse imageObj = (await AddImageToS3Bucket(image, bucketClient))[0];
                productImages.Add(new ProductImage {
                    ImageUrl = imageObj?.ActualObjectUrl ?? "Alt --", IsCoverImage = false
                });
            }

            //add available colours
            List <string> availableColours = new List <string>();

            foreach (int c in product.AvailableProductColours)
            {
                var colour = (ProductColour)c;
                availableColours.Add(colour.ToString());
            }

            //map reqObj to product entity
            var productEntity = _mapper.Map <Product>(product);

            productEntity.ProductImages       = productImages;
            productEntity.AllowedPaymentPlans = productPlans;
            productEntity.TimeStampCreated    = DateTimeOffset.Now;
            productEntity.AvailableColours    = availableColours;

            var newProduct = await _productRepo.AddProductAsync(productEntity);

            if (newProduct == null)
            {
                return(null);
            }
            var result = _mapper.Map <ProductResponseObject>(newProduct);

            return(result);
        }