public ActionResult CreatePurchase(PurchaseViewModel purchase)
        {
            PurchaseRepository repo = new PurchaseRepository();

            var result = repo.CreatePurchase(purchase);

            return(result ? RedirectToAction("PurchaseSuccess") : RedirectToAction("PurchaseFailure"));
        }
Exemplo n.º 2
0
        //retailPlaceAddress - строка с адресом магазина
        public void ParseJsonData(Guid customerId)
        {
            ShopRepository        shopRepository        = new ShopRepository();
            CustomerRepository    customerRepository    = new CustomerRepository();
            PurchaseRepository    purchaseRepository    = new PurchaseRepository();
            ProductRepository     productRepository     = new ProductRepository();
            ProductItemRepository productItemRepository = new ProductItemRepository();

            Shop shop = shopRepository.CreateShop(
                (long)_jsonData["document"]["receipt"]["userInn"],
                (string)_jsonData["document"]["receipt"]["user"],
                (string)_jsonData["document"]["receipt"]["retailPlaceAddress"]);

            Customer customer = customerRepository.GetCustomer(customerId);

            Purchase purchase = purchaseRepository.CreatePurchase(
                customer.Id,
                shop.Id,
                (DateTime)_jsonData["document"]["receipt"]["dateTime"],
                (decimal)_jsonData["document"]["receipt"]["totalSum"] / 100);

            //purchase.CustomerId = customer.Id;
            //purchase.Customer = customer;

            //purchase.ShopId = shop.Id;
            //purchase.Shop = shop;

            //purchase.Date = (DateTime) _jsonData["document"]["receipt"]["dateTime"];
            //purchase.PurchaseSum = (decimal)_jsonData["document"]["receipt"]["totalSum"] / 100;

            JArray items = (JArray)_jsonData["document"]["receipt"]["items"];

            foreach (var item in items)
            {
                Product     product     = productRepository.CreateProduct((string)item["name"]);
                ProductItem productItem = productItemRepository.CreateProductItem(
                    product.Id,
                    purchase.Id,
                    (decimal)item["price"] / 100,
                    (decimal)item["quantity"],
                    (decimal)item["sum"] / 100);
                //ProductItem productItem = new ProductItem();
                //productItem.Price = (decimal) item["price"] / 100;
                //productItem.Quantity = (decimal) item["quantity"];
                //productItem.Sum = (decimal) item["sum"] / 100;
                //productItem.ProductId = product.Id;
                //productItem.Product = product;
                //productItem.PurchaseId = purchase.Id;
                //productItem.Purchase = purchase;
            }
            Console.WriteLine("Parsed and added to database.");
        }
        public Invoice MakePurchase(Customer customer,
                                    Product product, Discount discount)
        {
            var purchase
                = purchaseRepository.CreatePurchase(customer);

            purchaseRepository.AddProduct(purchase, product);
            var invoice
                = purchaseRepository.CreateInvoice(purchase);

            if (discount != null)
            {
                invoice.ApplyDiscount(discount);
            }
            return(invoice);
        }
Exemplo n.º 4
0
        public void ShouldCreatePurchase()
        {
            string customerMail = "*****@*****.**";
            Guid   shopId       = new Guid("DF058C1F-B253-E811-BFD6-001583C810FA");

            CustomerRepository customerRepo = new CustomerRepository();
            ShopRepository     shopRepo     = new ShopRepository();
            PurchaseRepository purchaseRepo = new PurchaseRepository();

            Shop     shop     = shopRepo.GetShop(shopId);
            Customer customer = customerRepo.GetCustomer(customerMail);
            Purchase purchase = purchaseRepo.CreatePurchase(customer.Id, shop.Id, DateTime.Now, new decimal(123.45));

            Assert.AreEqual(customer.Id, purchase.CustomerId);
            Assert.AreEqual(shopId, purchase.ShopId);
            Assert.AreEqual(new decimal(123.45), purchase.PurchaseSum);
        }
Exemplo n.º 5
0
        public void ShouldCreatePurchaseWithItems()
        {
            Guid customerId = new Guid("296BE888-B153-E811-BFD6-001583C810FA");
            Guid shopId     = new Guid("DF058C1F-B253-E811-BFD6-001583C810FA");
            Guid product1Id = new Guid("D309B217-BE53-E811-BFD6-001583C810FA");
            Guid product2Id = new Guid("DD09B217-BE53-E811-BFD6-001583C810FA");
            Guid product3Id = new Guid("DE09B217-BE53-E811-BFD6-001583C810FA");
            Guid product4Id = new Guid("E809B217-BE53-E811-BFD6-001583C810FA");

            PurchaseRepository purchaseRepository = new PurchaseRepository();
            Purchase           purchase           = purchaseRepository.CreatePurchase(
                customerId,
                shopId,
                DateTime.Now,
                500);

            ProductItemRepository productItemRepository = new ProductItemRepository();
            ProductItem           productItem1          = productItemRepository.CreateProductItem(
                product1Id,
                purchase.Id,
                100,
                1,
                100);
            ProductItem productItem2 = productItemRepository.CreateProductItem(
                product2Id,
                purchase.Id,
                100,
                1,
                100);
            ProductItem productItem3 = productItemRepository.CreateProductItem(
                product3Id,
                purchase.Id,
                100,
                1,
                100);
            ProductItem productItem4 = productItemRepository.CreateProductItem(
                product4Id,
                purchase.Id,
                100,
                1,
                100);
        }