Пример #1
0
        public static void Main(string[] args)
        {
            IDataGetter           dataGetter           = new ConsoleDataGetter();
            IUnitOfWork           unitOfWork           = new UnitOfWork(new BookingDbContext());
            IProductInShopService productInShopService = new ProductInShopService(unitOfWork);
            IUserService          userService          = new UserService(unitOfWork);
            IBookingService       bookingService       = new BookingService(productInShopService, unitOfWork);
            User currentUser = null;

            while (currentUser == null)
            {
                currentUser = userService.GetUserByLoginAndPassword(dataGetter.GetUserLogin(), dataGetter.GetUserPassword());
            }
            bool wantMore = true;

            while (wantMore)
            {
                IList <ProductInShop> productInShops = productInShopService.GetProductInShopsByProductName(dataGetter.GetProductName());
                while (productInShops.Count == 0)
                {
                    Console.WriteLine("No products were found. Try another product name...");
                    productInShops = productInShopService.GetProductInShopsByProductName(dataGetter.GetProductName());
                }
                ProductInShop selectedProduct = dataGetter.GetSelectedProductInShop(productInShops);
                DateTime      endDate         = dataGetter.GetBookingPeriod();
                bookingService.MakeBooking(currentUser, selectedProduct, DateTime.Now, endDate);
                Console.WriteLine("Thank you for booking");
                Console.WriteLine("Do you want to continue? (yes/no)");
                wantMore = Console.ReadLine().ToLower().Equals("yes");
            }
        }
        public void AddPromotionPrice_ShouldAddPriceToProductInShopAndSetPropertyIsPromotionOnTrue()
        {
            var product       = new Product("Test", "TestVendor", 1, Enums.SizeUnits.l, 1);
            var productInShop = ProductInShop.CreateProductInShop(product, 1);

            var price = new Price();

            productInShop.AddPromotionPrice(price);

            productInShop.Prices.Should().NotBeEmpty();
            productInShop.Prices.Should().Contain(price);
            price.IsPromotionPrice.Should().BeTrue();
        }
        public void CreateProductInShop_ShouldCreateProductInShop()
        {
            var product = new Product("Test", "TestVendor", 1, Enums.SizeUnits.l, 1);
            var shopId  = 1;

            var productInShop = ProductInShop.CreateProductInShop(product, shopId);

            productInShop.Should().NotBeNull();
            productInShop.Product.Should().NotBeNull();
            productInShop.Product.Should().BeSameAs(product);
            productInShop.ShopId.Should().Be(shopId);

            product.ProductInShops.Should().NotBeEmpty();
            product.ProductInShops.Should().Contain(productInShop);
        }
Пример #4
0
 public void OnSuccessBuy(Merchandise merchandise, ProductInShop productInShop)
 {
     if (merchandise.costType == CostType.Pearl)
     {
         if (EntireGameManager.getInstance().getPlayerData().pearl < merchandise.cost)
         {
             Debug.Log("珍珠不足");
             MainUIManager.CreateCheckBox(() => { }, "珍珠不足");
             return;
         }
         else
         {
             EntireGameManager.getInstance().playerData.pearl -= merchandise.cost;
         }
     }
     else
     {
         if (EntireGameManager.getInstance().getPlayerData().sugar < merchandise.cost)
         {
             MainUIManager.CreateCheckBox(() => { }, "方糖不足");
             Debug.Log("方糖不足");
             return;
         }
         else
         {
             EntireGameManager.getInstance().playerData.sugar -= merchandise.cost;
         }
     }
     Debug.Log("成功購買" + merchandise.chineseName);
     if (merchandise.type == MerchandiseType.Animal)
     {
         EntireGameManager.getInstance().getPlayerData().animalList.Add(merchandise.indexName);
     }
     else if (merchandise.type == MerchandiseType.Cup)
     {
         EntireGameManager.getInstance().getPlayerData().cupList.Add(merchandise.indexName);
     }
     else if (merchandise.type == MerchandiseType.Liquid)
     {
         EntireGameManager.getInstance().getPlayerData().liquidList.Add(merchandise.indexName);
     }
     productInShop.HaveProduct(true);
     EntireGameManager.getInstance().Save();
     AudioManager.Play("purchase");
     UpdateMoney();
 }
Пример #5
0
        private static async Task CreateProducts(ShoppingHelperDbContext dbContext, ILogger <ShoppingHelperContextSeed> logger)
        {
            if (await dbContext.Products.AnyAsync())
            {
                logger.LogInformation("Products are already inserted.");
                return;
            }

            var laptop     = new Product("Laptop", "Asus", null, null, 1);
            var appleJuice = new Product("Apple juice", "AppleVendor", 2, Domain.Enums.SizeUnits.l, 2);

            dbContext.Products.Add(laptop);
            dbContext.Products.Add(appleJuice);

            await dbContext.SaveChangesAsync();

            var laptopInAmazon = ProductInShop.CreateProductInShop(laptop, 1);

            laptopInAmazon.AddBasePrice(new Price {
                PriceValue = 3333
            });

            var laptopInSuperShop = ProductInShop.CreateProductInShop(laptop, 2);

            laptopInSuperShop.AddBasePrice(new Price {
                PriceValue = 3000
            });

            var appleJuiceInSuperShop = ProductInShop.CreateProductInShop(appleJuice, 2);

            appleJuiceInSuperShop.AddBasePrice(new Price {
                PriceValue = 4, PricePerSizeUnit = 2, SizeUnit = Domain.Enums.SizeUnits.l
            });
            appleJuiceInSuperShop.AddPromotionPrice(new Price {
                PriceValue = 2.50m, PricePerSizeUnit = 1.25m, SizeUnit = Domain.Enums.SizeUnits.l, PromotionConstraints = "If you use special coupon."
            });

            dbContext.ProductsInShops.Add(laptopInAmazon);
            dbContext.ProductsInShops.Add(laptopInSuperShop);
            dbContext.ProductsInShops.Add(appleJuiceInSuperShop);

            await dbContext.SaveChangesAsync();

            logger.LogInformation("Products created.");
        }
Пример #6
0
    public void OnBuyClicked(Merchandise merchandise, ProductInShop productInShop)
    {
        if (merchandise.type == MerchandiseType.Animal && isSlidingAnimal)
        {
            return;
        }
        else if (merchandise.type == MerchandiseType.Cup && isSlidingCup)
        {
            return;
        }
        else if (merchandise.type == MerchandiseType.Liquid && isSlidingLiquid)
        {
            return;
        }
        string costType = "方糖";

        if (merchandise.costType == CostType.Pearl)
        {
            costType = "珍珠";
        }
        MainUIManager.CreateDialogBox(() => OnSuccessBuy(merchandise, productInShop), CancelBuy, "確定要花費" + merchandise.cost + costType + "購買" + merchandise.chineseName + "嗎?");
    }
Пример #7
0
            public async Task <int> Handle(CreateProductCommand request, CancellationToken cancellationToken)
            {
                await this.validator.ValidateAndThrowAsync(request, cancellationToken);

                if (await this.categoryRepository.GetByIdAsync(request.CategoryId) == null)
                {
                    throw new NotFoundException(nameof(Category));
                }

                if (await this.shopRepository.GetByIdAsync(request.ShopId) == null)
                {
                    throw new NotFoundException(nameof(Shop));
                }

                var product = new Product(request.Name, request.Vendor, request.Size?.Value, request.Size?.Unit.ToEnum <SizeUnits>(), request.CategoryId);

                if (await this.productRepository.DoesProductExist(product))
                {
                    throw new BadRequestException($"Product '{product.Name}({product.Vendor})' already exist.");
                }

                if (await this.productInShopRepository.DoesProductExistInShop(product, request.ShopId))
                {
                    throw new BadRequestException($"Product '{product.Name}({product.Vendor})' already exist in shop.");
                }

                var productInShop = ProductInShop.CreateProductInShop(product, request.ShopId);

                productInShop.AddBasePrice(mapper.Map <Price>(request.BasePrice));

                if (request.PromotionPrice != null)
                {
                    productInShop.AddPromotionPrice(mapper.Map <Price>(request.PromotionPrice));
                }

                await this.productInShopRepository.AddAsync(productInShop);

                return(product.Id);
            }
            public async Task <Unit> Handle(AddPriceToProductCommand request, CancellationToken cancellationToken)
            {
                await this.validator.ValidateAndThrowAsync(request, cancellationToken);

                if (await this.shopRepository.GetByIdAsync(request.ShopId) == null)
                {
                    throw new NotFoundException(nameof(Shop));
                }

                if (await this.productRepository.GetByIdAsync(request.ProductId) == null)
                {
                    throw new NotFoundException(nameof(Product));
                }

                var productInShop = await this.productInShopRepository.GetProductInShop(request.ProductId, request.ShopId);

                if (productInShop == null)
                {
                    productInShop = new ProductInShop()
                    {
                        ShopId    = request.ShopId,
                        ProductId = request.ProductId
                    };

                    await this.productInShopRepository.AddAsync(productInShop);
                }

                productInShop.AddBasePrice(mapper.Map <Price>(request.BasePrice));

                if (request.PromotionPrice != null)
                {
                    productInShop.AddPromotionPrice(mapper.Map <Price>(request.PromotionPrice));
                }

                await this.productInShopRepository.UpdateAsync(productInShop);

                return(Unit.Value);
            }
 public void IncreaseQuantity(ProductInShop model)
 {
     model.Quantity += 1;
     unitOfWork.ProductInShopRepository.Update(productInShopMapper.ToEntity(model));
 }
Пример #10
0
 void AddProduct(Merchandise product, MerchandiseType type, int index)
 {
     if (type == MerchandiseType.Animal)
     {
         RectTransform rect = Instantiate(AnimalProductPrefab, animalShop).GetComponent <RectTransform>();
         float         x    = index * itemWidth;
         rect.anchoredPosition = new Vector2(x, rect.anchoredPosition.y);
         ProductInShop prod = rect.GetComponent <ProductInShop>();
         prod.icon.sprite   = product.SelectViewSprite;
         prod.nameText.text = product.chineseName;
         prod.costText.text = "x" + product.cost;
         prod.SetCostType(product.costType);
         if (EntireGameManager.getInstance().getPlayerData().HaveItem(type, product.indexName))
         {
             prod.HaveProduct(true);
         }
         else
         {
             prod.HaveProduct(false);
         }
         prod.Cover.gameObject.GetComponent <Button>().onClick.AddListener(() => OnBuyClicked(product, prod));
     }
     else if (type == MerchandiseType.Cup)
     {
         RectTransform rect = Instantiate(CupProductPrefab, cupShop).GetComponent <RectTransform>();
         float         x    = index * itemWidth;
         rect.anchoredPosition = new Vector2(x, rect.anchoredPosition.y);
         ProductInShop prod = rect.GetComponent <ProductInShop>();
         prod.icon.sprite   = product.SelectViewSprite;
         prod.nameText.text = product.chineseName;
         prod.costText.text = "x" + product.cost;
         prod.SetCostType(product.costType);
         if (EntireGameManager.getInstance().getPlayerData().HaveItem(type, product.indexName))
         {
             prod.HaveProduct(true);
         }
         else
         {
             prod.HaveProduct(false);
         }
         prod.Cover.gameObject.GetComponent <Button>().onClick.AddListener(() => OnBuyClicked(product, prod));
     }
     else if (type == MerchandiseType.Liquid)
     {
         RectTransform rect = Instantiate(LiquidProductPrefab, liquidShop).GetComponent <RectTransform>();
         float         x    = index * itemWidth;
         rect.anchoredPosition = new Vector2(x, rect.anchoredPosition.y);
         ProductInShop prod = rect.GetComponent <ProductInShop>();
         prod.nameText.text = product.chineseName;
         prod.costText.text = "x" + product.cost;
         prod.SetCostType(product.costType);
         if (EntireGameManager.getInstance().getPlayerData().HaveItem(type, product.indexName))
         {
             prod.HaveProduct(true);
         }
         else
         {
             prod.HaveProduct(false);
         }
         prod.Cover.gameObject.GetComponent <Button>().onClick.AddListener(() => OnBuyClicked(product, prod));
     }
 }
Пример #11
0
        public static void ImportProductsFromExcelFile(string filename, ApplicationDbContext context, TaskDescription task, int shopID)
        {
            long total = GetRowsCountToImport(filename);

            int count = 0;

            var productsInShop = new List <ProductInShop>();

            productsInShop.Capacity = 1000;

            var products = context.Products;

            var properties = typeof(ProductInShop).GetProperties();

            var propToCol = new Dictionary <string, PropertyInfo>();

            var logsWriter = new StreamWriter(File.Create(Path.ChangeExtension(filename, ".log")));

            task.Start();

            using (var package = new ExcelPackage(new FileInfo(filename)))
            {
                foreach (var worksheet in package.Workbook.Worksheets)
                {
                    string col = "A";
                    var    sb  = new StringBuilder(col);

                    while (worksheet.Cells[$"{col}1"].Value != null && worksheet.Cells[$"{col}1"].Value.ToString() != "")
                    {
                        var prop = properties.FirstOrDefault(p => p.Name == propOrder[col]);

                        if (prop != null)
                        {
                            propToCol[col] = prop;
                        }
                        else if ("SKU" == worksheet.Cells[$"{col}1"].Value.ToString() || "Name" == worksheet.Cells[$"{col}1"].Value.ToString())
                        {
                            propToCol[col] = null;
                        }

                        col = sb.Append(sb[sb.Length - 1]++, 1).Remove(sb.Length - 1, 1).ToString();

                        if (sb.ToString().EndsWith("["))
                        {
                            sb  = new StringBuilder("AA");
                            col = sb.ToString();
                        }
                    }

                    int row = 3;
                    while (worksheet.Cells[$"A{row}"].Value != null && worksheet.Cells[$"A{row}"].Value.ToString().Length != 0)
                    {
                        string SKU           = "";
                        var    productInShop = new ProductInShop();

                        foreach (var pair in propToCol)
                        {
                            var prop = pair.Value;
                            col = pair.Key;

                            var value = worksheet.Cells[$"{col}{row}"].Value?.ToString();

                            if (prop == null)
                            {
                                if (propOrder[col] == "SKU")
                                {
                                    SKU = value;
                                }
                                continue;
                            }

                            if (prop.PropertyType == typeof(Boolean) && value != null)
                            {
                                prop.SetValue(productInShop, value != "0");
                            }
                            else if (value != null && value != "")
                            {
                                prop.SetValue(productInShop, Convert.ChangeType(value, prop.PropertyType));
                            }
                        }

                        productInShop.ShopID       = shopID;
                        productInShop.CreationDate = DateTime.Now;

                        var product = products.Where(p => p.SKU.EndsWith(SKU));

                        if (product != null && product.Count() == 1 && SKU.Length > 4)
                        {
                            productInShop.ProductID = product.First().ID;
                            productsInShop.Add(productInShop);
                        }
                        else if (product != null)
                        {
                            logsWriter.WriteLine($"Error: Line {row} - Product with SKU = {SKU} is absent in global product table.");
                        }
                        else if (product.Count() != 1)
                        {
                            logsWriter.WriteLine($"Error: Line {row} - There are more than one product acoording to SKU = {SKU} in global product table.");
                        }
                        else if (SKU.Length < 5)
                        {
                            logsWriter.WriteLine($"Error: Line {row} - Product SKU = {SKU} in short.");
                        }

                        ++row;
                        if (row % 100 == 0)
                        {
                            context.ProductInShops.AddRange(productsInShop);
                            context.SaveChanges();

                            productsInShop.Clear();

                            task.Progress = row * 100 / total;
                        }
                    }

                    count += row - 3;
                }
            }

            context.ProductInShops.AddRange(productsInShop);
            context.SaveChanges();

            task.Progress = 100;

            logsWriter.Close();

            return;
        }
 public Booking MakeBooking(User user, ProductInShop productInShop, DateTime startDate, DateTime endDate)
 {
     return(bookingService.MakeBooking(user, productInShop, startDate, endDate));
 }