コード例 #1
0
ファイル: Program.cs プロジェクト: mustee/GroceryCo
        static void Main(string[] args)
        {
            //var promotions = new Promotion[]
            //{
            //    new Promotion("Additional Sale test", "Orange", PromotionType.AdditionalSale, 2, 0, 0.5f, DateTime.UtcNow.AddDays(-2), DateTime.UtcNow.AddDays(1), null)
            //};

            //var json = JsonConvert.SerializeObject(promotions);
            //System.Console.WriteLine(json);

            var products = new FileReader("Files/items.txt")
                           .Read()
                           .Split("\n")
                           .Where(s => !string.IsNullOrWhiteSpace(s))
                           .Select(s => s.Trim());

            var productRepository   = new ProductRepository(new FileReader("Files/products.json"), new JsonTextSerializer());
            var promotionRepository = new PromotionRepository(new FileReader("Files/promotions.json"), new JsonTextSerializer());

            var saleService = new SaleService(productRepository, new PriceResolver(promotionRepository));
            var sale        = saleService.Checkout(products.ToArray());

            var receiptService = new ReceiptService();

            receiptService.Print(sale);

            System.Console.Read();
        }
コード例 #2
0
        private void ApplyPromotion(int lastAlteredproductId, ProductType productType)
        {
            var cartProducts = GetCartProducts(lastAlteredproductId);
            ProductPromotion productPromotion;

            if (productType == ProductType.Product)
            {
                productPromotion = ProductPromotionRepository.GetProductPromotionByProductId(lastAlteredproductId);
            }
            else if (productType == ProductType.PromoProduct)
            {
                productPromotion = ProductPromotionRepository.GetProductPromotionByPromoProductId(lastAlteredproductId);
            }
            else
            {
                throw new Exception("greska");
            }

            var promotion = PromotionRepository.GetPromotion(productPromotion.PromotionId);

            if (IsProductInCart(productPromotion.PromotionalProductId, false))
            {
                RemoveCartProduct(productPromotion.PromotionalProductId);
                AddCartProduct(productPromotion.PromotionalProductId, productPromotion.PromotionId);
            }
        }
コード例 #3
0
        //--------------------------------------------------------------------

        /**
         * Constructeur
         */
        public ShowPromotionViewModel(int promotion_id)
        {
            promotionRepository = new PromotionRepository();
            featureRepository   = new FeatureRepository();
            Promotion           = promotionRepository.GetPromotion(promotion_id);
            Features            = featureRepository.GetFeatures();
        }
コード例 #4
0
        public IHttpActionResult GetLatestPromotion(int Type)
        {
            PromotionModel promotion = null;

            try
            {
                using (AppDBContext context = new AppDBContext())
                {
                    var p = new PromotionRepository(context).GetLatestPromotion(Type);

                    if (p != null)
                    {
                        promotion = new PromotionModel
                        {
                            Id          = p.Id,
                            Title       = p.Title,
                            Header      = p.Header,
                            Description = p.Description,
                            CreatedDate = p.CreatedDate?.ToString(Constant.DateFormatType.YYYYMMDD),
                            Status      = p.Status ?? 0,
                            Type        = ((p.Type ?? 0) == Constant.PromotionType.OFFER) ? "Offers" : "Promotions"
                        };
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(typeof(PromotionController), ex.Message + ex.StackTrace, LogType.ERROR);
                return(InternalServerError(ex));
            }

            return(Ok(promotion));
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: jaison-b/CheckoutApp
        private static void CheckOut(Options options)
        {
            IProductRepository   productRepository   = new ProductRepository(File.OpenRead(options.ProductInputFile));
            IPromotionRepository promotionRepository = new PromotionRepository(File.OpenRead(options.PromotionInputFile));
            ICartFactory         cartFactory         = new CartFactory(promotionRepository, productRepository);
            var cart = cartFactory.CreateCart(File.OpenRead(options.OrderInputFile), DateTime.Now);

            cart.Checkout();
        }
コード例 #6
0
        public void CanCreateAPromotion()
        {
            Promotion           p = new Promotion();
            PromotionRepository r = PromotionRepository.InstantiateForMemory(new RequestContext());

            Assert.IsTrue(r.Create(p), "Create should be true");
            Assert.IsNotNull(p);
            Assert.IsTrue(p.Id > 0, "Promotion was not assigned an Id number");
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public List <PromotionModel> GetPromotions()
        {
            var items = PromotionRepository.GetAll();

            if (items != null)
            {
                return(items.Select(p => p.ToModel()).ToList());
            }
            return(new List <PromotionModel>());
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: intersite1974/acmecheckout
        static void Main(string[] args)
        {
            var validationEngine    = new ValidationService();
            var discountService     = new DiscountService();
            var promotionRepository = new PromotionRepository();
            var itemPriceCalculator = new ItemPriceCalculatorService(promotionRepository, validationEngine, discountService);

            // Add Promotions
            promotionRepository.AddPromotion(new Promotion {
                PromotionId = 1, Description = "'X' for 'N' Promotion", PromotionPrice = 40.00M, QuantityTrigger = 3, PromotionPercentageReduction = 0.00M
            });
            promotionRepository.AddPromotion(new Promotion {
                PromotionId = 2, Description = "'X'% off for every 'N' purchased together Promotion", PromotionPrice = 40.00M, QuantityTrigger = 2, PromotionPercentageReduction = 25.00M
            });

            // Prep. Items
            var testItem1 = new Item {
                SkuId = "A", PromotionId = 0, Description = "Test Widget 1", UnitPrice = 10.00M
            };
            var testItem2 = new Item {
                SkuId = "B", PromotionId = 1, Description = "Test Widget 2", UnitPrice = 15.00M
            };
            var testItem3 = new Item {
                SkuId = "C", PromotionId = 0, Description = "Test Widget 3", UnitPrice = 40.00M
            };
            var testItem4 = new Item {
                SkuId = "D", PromotionId = 2, Description = "Test Widget 4", UnitPrice = 55.00M
            };

            var shoppingBasket = new ShoppingBasketService(itemPriceCalculator, validationEngine);

            // Add Sample Items to Basket
            var cartGrandTotal = 0.00M;

            // A
            shoppingBasket.TryAddItemToBasket(testItem1, 8, out var cartSubTotal1);
            cartGrandTotal = cartSubTotal1;

            // B
            shoppingBasket.TryAddItemToBasket(testItem2, 7, out var cartSubTotal2);
            cartGrandTotal = cartSubTotal2;

            // C
            shoppingBasket.TryAddItemToBasket(testItem3, 5, out var cartSubTotal3);
            cartGrandTotal = cartSubTotal3;

            // D
            shoppingBasket.TryAddItemToBasket(testItem4, 3, out var cartSubTotal4);
            cartGrandTotal = cartSubTotal4;

            Console.WriteLine($"Total Cost of Basket: £{cartGrandTotal}");
            Console.WriteLine("Press any key to exit the application..");
            Console.ReadKey(false);
        }
コード例 #9
0
        public void Promotion_CanCreateAPromotion()
        {
            var app = CreateHccAppInMemory();

            var p = new Promotion();
            var r = new PromotionRepository(new HccRequestContext());

            Assert.IsTrue(r.Create(p), "Create should be true");
            Assert.IsNotNull(p);
            Assert.IsTrue(p.Id > 0, "Promotion was not assigned an Id number");
        }
コード例 #10
0
        public CartProduct(int baseProductId, int promotionId)
        {
            var baseProduct = ProductRepository.GetProduct(baseProductId);
            var promotion   = PromotionRepository.GetPromotion(promotionId);

            Id          = baseProduct.Id;
            Name        = baseProduct.Name;
            Price       = GetPriceWithPromotion(baseProduct.Price, promotion.Amount);
            Quantity    = 1;
            IsPromotion = true;
        }
コード例 #11
0
        public Task <decimal> GetCartPriceWithPromotion(Cart cartList)
        {
            return(Task.Run(() =>
            {
                //Get all active Promotions from the
                PromotionRepository _promotionRepository = new PromotionRepository();
                var activePromotionsList = _promotionRepository.GetActivePromotions();

                //Load active promotions
                cartList.LoadPromotions(activePromotionsList);
                return cartList.CalculatePromotionOnCardValue();
            }));
        }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public DatatablesView <PromotionModel> GetPromotionsByPaging(DataTablesPaging request)
        {
            int total       = 0;
            var pagingItems = PromotionRepository.GetItemsByPaging(request, out total);
            var items       = new List <PromotionModel>();

            foreach (var pagingItem in pagingItems)
            {
                var item = pagingItem.ToModel();
                items.Add(item);
            }
            return(new DatatablesView <PromotionModel>(request.Draw, total, pagingItems.Count, items));
        }
コード例 #13
0
        public UnitOfWork()
        {
            _context.Configuration.LazyLoadingEnabled = true;

            Brand           = new BrandRepository(_context);
            Category        = new CategoryRepository(_context);
            Customer        = new CustomerRepository(_context);
            CustomerAddress = new CustomerAddressRepository(_context);
            File            = new FileRepository(_context);
            Product         = new ProductRepository(_context);
            Promotion       = new PromotionRepository(_context);
            ProductParent   = new ProductParentRepository(_context);
            Provider        = new ProviderRepository(_context);
        }
コード例 #14
0
 public UnitOfWork()
 {
     Client              = new ClientRepository(_context);
     Order               = new OrderRepository(_context);
     OrderItem           = new OrderItemRepository(_context);
     Pet                 = new PetRepository(_context);
     Product             = new ProductRepository(_context);
     Promotion           = new PromotionRepository(_context);
     Service             = new ServiceRepository(_context);
     ServicePriceHistory = new ServicePriceHistoryRepository(_context);
     ServiceSchedule     = new ServiceScheduleRepository(_context);
     User                = new UserRepository(_context);
     UserAvaliation      = new UserAvaliationRepository(_context);
 }
コード例 #15
0
        private bool ArePromotionRequirementsMet(int productId, int promotionId)
        {
            var promotion        = PromotionRepository.GetPromotion(promotionId);
            var productPromotion = ProductPromotionRepository.GetProductPromotionByPromotionId(promotionId);

            int numberOfProducts                  = GetNumberOfProductsInCart(productId);
            int numberOfRequiredproducts          = promotion.NumberOfRequiredproducts;
            int numberOfPromotionalProductsInCart = GetCartProducts(productPromotion.PromotionalProductId).FirstOrDefault(p => p.IsPromotion) == null ? 0 : GetCartProducts(productPromotion.PromotionalProductId).FirstOrDefault(p => p.IsPromotion).Quantity;

            if (GetCartProducts(productPromotion.PromotionalProductId).FirstOrDefault(p => p.IsPromotion) != null && GetCartProducts(productPromotion.PromotionalProductId).FirstOrDefault(p => p.IsPromotion).Quantity >= promotion.MaximumOccurances)
            {
                return(false);
            }
            return(numberOfProducts >= numberOfRequiredproducts && (numberOfPromotionalProductsInCart == 0 || (numberOfProducts / numberOfRequiredproducts > numberOfPromotionalProductsInCart)));
        }
コード例 #16
0
        protected async Task <PromotionEntity> GetPromotionEntity(int id)
        {
            var promotionE = await PromotionRepository.SingleOrDefaultAsync(e => e.Id == id) ?? throw new BusinessException();

            if (DateTime.Compare(promotionE.ExpireDate.ClearTime(), DateTime.Now.ClearTime()) <= 0)
            {
                throw new BusinessException();
            }

            if (!promotionE.IsOneTime && promotionE.NoOfTimes < 1)
            {
                throw new BusinessException();
            }

            return(promotionE);
        }
コード例 #17
0
        public void CanFindPromotionInRepository()
        {
            Promotion p = new Promotion();

            p.Name = "FindMe";
            PromotionRepository r = PromotionRepository.InstantiateForMemory(new RequestContext());

            Assert.IsTrue(r.Create(p), "Create should be true");
            Assert.IsNotNull(p);
            Assert.IsTrue(p.Id > 0, "Promotion was not assigned an Id number");

            Promotion target = r.Find(p.Id);

            Assert.IsNotNull(target, "Found should not be null");
            Assert.AreEqual(p.Id, target.Id, "Id didn't match");
            Assert.AreEqual(p.StoreId, target.StoreId, "Store ID Didn't Match");
            Assert.AreEqual(p.Name, target.Name, "Name didn't match");
        }
コード例 #18
0
        public void Promotion_CanSaveQualificationsAndActionsInRepository()
        {
            var app = CreateHccAppInMemory();

            var p = new Promotion {
                Mode = PromotionType.Sale, Name = "FindMe"
            };

            p.AddQualification(new ProductBvin(new List <string> {
                "ABC123"
            }));
            p.AddQualification(new ProductType("TYPE0"));
            p.AddAction(new ProductPriceAdjustment(AmountTypes.Percent, 50));
            var r = new PromotionRepository(new HccRequestContext());


            Assert.IsTrue(r.Create(p), "Create should be true");
            Assert.IsNotNull(p);
            Assert.IsTrue(p.Id > 0, "Promotion was not assigned an Id number");

            var target = r.Find(p.Id);

            Assert.IsNotNull(target, "Found should not be null");
            Assert.AreEqual(p.Id, target.Id, "Id didn't match");
            Assert.AreEqual(p.StoreId, target.StoreId, "Store ID Didn't Match");
            Assert.AreEqual(p.Name, target.Name, "Name didn't match");

            Assert.AreEqual(p.Qualifications.Count, target.Qualifications.Count, "Qualification count didn't match");
            for (var i = 0; i < p.Qualifications.Count; i++)
            {
                Assert.AreEqual(p.Qualifications[0].Id, target.Qualifications[0].Id,
                                "Id of index " + i + " didn't match");
                Assert.AreEqual(p.Qualifications[0].GetType(), target.Qualifications[0].GetType(),
                                "Type of index " + i + " didn't match");
            }

            Assert.AreEqual(p.Actions.Count, target.Actions.Count, "Action count didn't match");
            for (var i = 0; i < p.Actions.Count; i++)
            {
                Assert.AreEqual(p.Actions[0].Id, target.Actions[0].Id, "Id of action index " + i + " didn't match");
                Assert.AreEqual(p.Actions[0].GetType(), target.Actions[0].GetType(),
                                "Type of action index " + i + " didn't match");
            }
        }
コード例 #19
0
        public void Promotion_CanFindPromotionInRepository()
        {
            var app = CreateHccAppInMemory();

            var p = new Promotion();

            p.Name = "FindMe";
            var r = new PromotionRepository(new HccRequestContext());

            Assert.IsTrue(r.Create(p), "Create should be true");
            Assert.IsNotNull(p);
            Assert.IsTrue(p.Id > 0, "Promotion was not assigned an Id number");

            var target = r.Find(p.Id);

            Assert.IsNotNull(target, "Found should not be null");
            Assert.AreEqual(p.Id, target.Id, "Id didn't match");
            Assert.AreEqual(p.StoreId, target.StoreId, "Store ID Didn't Match");
            Assert.AreEqual(p.Name, target.Name, "Name didn't match");
        }
コード例 #20
0
        public void CanUpdateNameOfPromotion()
        {
            Promotion p = new Promotion();

            p.Name = "Old";
            PromotionRepository r = PromotionRepository.InstantiateForMemory(new RequestContext());

            r.Create(p);

            string updatedName = "New";

            p.Name = updatedName;
            Assert.IsTrue(r.Update(p), "Update should be true");
            Promotion target = r.Find(p.Id);

            Assert.IsNotNull(target, "Found should not be null");
            Assert.AreEqual(p.Id, target.Id, "Id didn't match");
            Assert.AreEqual(p.StoreId, target.StoreId, "Store ID Didn't Match");
            Assert.AreEqual("New", target.Name, "Name didn't match");
        }
コード例 #21
0
        public void Promotion_CanUpdateNameOfPromotion()
        {
            var app = CreateHccAppInMemory();

            var p = new Promotion();

            p.Name = "Old";
            var r = new PromotionRepository(new HccRequestContext());

            r.Create(p);

            var updatedName = "New";

            p.Name = updatedName;
            Assert.IsTrue(r.Update(p), "Update should be true");
            var target = r.Find(p.Id);

            Assert.IsNotNull(target, "Found should not be null");
            Assert.AreEqual(p.Id, target.Id, "Id didn't match");
            Assert.AreEqual(p.StoreId, target.StoreId, "Store ID Didn't Match");
            Assert.AreEqual("New", target.Name, "Name didn't match");
        }
コード例 #22
0
        public async void GetCartPriceWithPromotion_Combined_response()
        {
            //Arrange
            ProductRepository productContext = new ProductRepository();
            var products = productContext.Products;

            PromotionRepository promotionDB = new PromotionRepository();
            var activePromotionList         = promotionDB.GetActivePromotions();

            Cart objCart = new Cart();

            objCart.AddProduct(products.First(p => p.SKU == "C"), 5);
            objCart.AddProduct(products.First(p => p.SKU == "D"), 5);
            objCart.LoadPromotions(activePromotionList);


            //Act
            var result = await _sut.GetCartPriceWithPromotion(objCart);

            //Assert
            Assert.NotEqual(0, result);
            Assert.Equal(170, result);
        }
コード例 #23
0
 public UnitOfWork(QLBHDienThoaiEntities context)
 {
     _context           = context;
     Product            = new ProductRepository(_context);
     Account            = new AccountRepository(_context);
     TypeProduct        = new TypeProductRepository(_context);
     Supplier           = new SupplierRespository(_context);
     Employee           = new EmployeeRepository(_context);
     OrderInvoice       = new OrderInvoiceRepository(_context);
     OrderInvoiceDetail = new OrderInvoiceDetailRepository(_context);
     Cart           = new CartRepository(_context);
     CartDetail     = new CartDetailRepository(_context);
     Promotion      = new PromotionRepository(_context);
     Customer       = new CustomerRepository(_context);
     BillOfSale     = new BillOfSaleRepository(_context);
     BillSaleDetail = new BillSaleDetailOfSaleRepository(_context);
     Payment        = new PaymentRepository(_context);
     Receipt        = new ReceiptRepository(_context);
     ReceiptDetail  = new ReceiptDetailRepository(_context);
     Pay            = new PayRepository(_context);
     PayDetail      = new PayDetailRepository(_context);
     Comment        = new CommentRepository(_context);
 }
コード例 #24
0
        public void GetTotalOrderBySenarioC()
        {
            //Senario C

            List <UnitPrice> unitPrices = new List <UnitPrice>();

            UnitPrice unitPriceA = new UnitPrice();

            unitPriceA.STUId   = "A";
            unitPriceA.Value   = 50;
            unitPriceA.UnitQty = 5;
            unitPrices.Add(unitPriceA);

            UnitPrice unitPriceB = new UnitPrice();

            unitPriceB.STUId   = "B";
            unitPriceB.Value   = 30;
            unitPriceB.UnitQty = 5;
            unitPrices.Add(unitPriceB);

            UnitPrice unitPriceC = new UnitPrice();

            unitPriceC.STUId   = "C";
            unitPriceC.Value   = 20;
            unitPriceC.UnitQty = 1;
            unitPrices.Add(unitPriceC);

            IPromotionRepository promotionRepository = new PromotionRepository();

            var controller = new PromotionController(promotionRepository);

            var result = controller.CalCulateOrderAmount(unitPrices) as ViewResult;

            var data = result.Model as OrderSummary;

            Assert.AreEqual(370, data.Total, "Total Order Value not correct");
        }
コード例 #25
0
        public static void CalculatePromotions()
        {
            ProductRepository productContext = new ProductRepository();
            var products = productContext.Products;

            PromotionRepository promotionDB = new PromotionRepository();
            var activePromotionList         = promotionDB.GetActivePromotions();

            Cart objCart = new Cart();

            objCart.AddProduct(products.First(p => p.SKU == "A"), 3);
            objCart.AddProduct(products.First(p => p.SKU == "B"), 5);
            objCart.AddProduct(products.First(p => p.SKU == "C"), 1);
            objCart.AddProduct(products.First(p => p.SKU == "D"), 1);


            objCart.LoadPromotions(activePromotionList);

            var result = objCart.CalculatePromotionOnCardValue();



            Console.WriteLine(string.Format("Total:{0}", result));
        }
コード例 #26
0
        public void CanSaveQualificationsAndActionsInRepository()
        {
            Promotion p = new Promotion();

            p.Name = "FindMe";
            p.AddQualification(new ProductBvin("ABC123"));
            p.AddQualification(new ProductType("TYPE0"));
            p.AddAction(new ProductPriceAdjustment(AmountTypes.Percent, 50));
            PromotionRepository r = PromotionRepository.InstantiateForMemory(new RequestContext());


            Assert.IsTrue(r.Create(p), "Create should be true");
            Assert.IsNotNull(p);
            Assert.IsTrue(p.Id > 0, "Promotion was not assigned an Id number");

            Promotion target = r.Find(p.Id);

            Assert.IsNotNull(target, "Found should not be null");
            Assert.AreEqual(p.Id, target.Id, "Id didn't match");
            Assert.AreEqual(p.StoreId, target.StoreId, "Store ID Didn't Match");
            Assert.AreEqual(p.Name, target.Name, "Name didn't match");

            Assert.AreEqual(p.Qualifications.Count, target.Qualifications.Count, "Qualification count didn't match");
            for (int i = 0; i < p.Qualifications.Count; i++)
            {
                Assert.AreEqual(p.Qualifications[0].Id, target.Qualifications[0].Id, "Id of index " + i.ToString() + " didn't match");
                Assert.AreEqual(p.Qualifications[0].GetType(), target.Qualifications[0].GetType(), "Type of index " + i.ToString() + " didn't match");
            }

            Assert.AreEqual(p.Actions.Count, target.Actions.Count, "Action count didn't match");
            for (int i = 0; i < p.Actions.Count; i++)
            {
                Assert.AreEqual(p.Actions[0].Id, target.Actions[0].Id, "Id of action index " + i.ToString() + " didn't match");
                Assert.AreEqual(p.Actions[0].GetType(), target.Actions[0].GetType(), "Type of action index " + i.ToString() + " didn't match");
            }
        }
コード例 #27
0
 public void RemoveCartProduct(int productId)
 {
     if (!ProductPromotionRepository.GetProductPromotions().Any(p => p.ProductId == productId))
     {
         RemoveCartProduct(productId, false);
     }
     else
     {
         var productPromotion = ProductPromotionRepository.GetProductPromotionByProductId(productId);
         var promotion        = PromotionRepository.GetPromotion(productPromotion.PromotionId);
         if (IsProductInCart(productPromotion.PromotionalProductId) &&
             (!ArePromotionRequirementsMet(productPromotion.ProductId, productPromotion.PromotionId) &&
              IsProductInCart(productPromotion.PromotionalProductId, true)))
         {
             RemoveCartProduct(productId, false);
             RemoveCartProduct(productPromotion.PromotionalProductId, true);
             AddCartProduct(productPromotion.PromotionalProductId);
         }
         else
         {
             RemoveCartProduct(productId, false);
         }
     }
 }
コード例 #28
0
 public void Setup()
 {
     _promotionRepository = new PromotionRepository(File.OpenRead(TestPromotionsFile));
 }
コード例 #29
0
 public void ParsePromotionsInputStream_OnInvalidFile_ShouldThrowException()
 {
     _promotionRepository = new PromotionRepository(File.OpenRead("TestData/test_invalid_promotions.txt"));
 }
コード例 #30
0
 public MarketingService(RequestContext c,
                       PromotionRepository promotions)
 {
     context = c;
     Promotions = promotions;
 }
コード例 #31
0
 public PromotionsController()
 {
     this.repo = new PromotionRepository();
 }
コード例 #32
0
 public PromotionService(PromotionRepository promotionRepository)
 {
     _promotionRepository = promotionRepository;
 }
コード例 #33
0
        public IHttpActionResult PromotionsWithSpecialization(string search, string sort, DateTime? date, long? specialization)
        {
            try
            {
                SelectRepository selectRepo = new SelectRepository();
                PromotionRepository promoRepo = new PromotionRepository();

                PromotionsSpecializationCollectionViewModel model = new PromotionsSpecializationCollectionViewModel();

                model.promotions = promoRepo.GetList(search, sort, date, specialization);
                model.specialization = selectRepo.Specializations(true);

                return Ok(model);
            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
            }
        }