Example #1
0
 public static CalculatedCartItemDTO ToDTO(this BoughtProduct boughtProduct)
 {
     return(new CalculatedCartItemDTO
     {
         ProductId = boughtProduct.ProductId,
         ReducePrice = boughtProduct.ReducePrice
     });
 }
        public void ChangeReducePriceByMemberPrice_Ten_Success()
        {
            const decimal REDUCE_PRICE     = 10;
            var           boughtProduct    = new BoughtProduct("productId", 1, 100, 0, 0, null, null);
            var           newBoughtProduct = boughtProduct.ChangeReducePriceByMemberPrice(REDUCE_PRICE);

            Assert.AreNotEqual(boughtProduct, newBoughtProduct);
            Assert.AreEqual(REDUCE_PRICE, newBoughtProduct.ReducePriceByMemberPrice);
        }
Example #3
0
        /**
         * Sell the selected product
         */
        public void SellProduct()
        {
            if (View.getLBoxClient().SelectedValue != null)
            {
                if (View.getLBoxProduct().SelectedValue != null)
                {
                    Client              selectedClt  = (Client)View.getLBoxClient().SelectedValue;
                    BoughtProduct       selectedPdt  = (BoughtProduct)View.getLBoxProduct().SelectedValue;
                    List <TimeInterest> TimeInterest = selectedPdt.Product.TimeInterests;
                    int     periode         = (int)(DateTime.Today.Date - selectedPdt.StartDate).TotalDays / 30;
                    Decimal TimeInterestPdt = Utils.FindTimeInterestSection(selectedPdt.StartDate, DateTime.Today, selectedPdt.Product.TimeInterests).Interest;
                    Decimal SillInterestPdt = Utils.FindSillInterestSection(selectedPdt.Price, selectedPdt.Product.SillInterests).Interest;
                    Decimal InterestRate    = 0;
                    Decimal InterestPdt     = 0;
                    if (TimeInterestPdt != 0)
                    {
                        InterestRate = (TimeInterestPdt + 100) * (SillInterestPdt + 100) / 100 - 100;
                        InterestPdt  = InterestRate / 100 * selectedPdt.Price;
                    }

                    DialogResult d = MessageBox.Show("You will have an interest rate : " + InterestRate.ToString("0.##") + " % and amount : " + InterestPdt.ToString("0.##") + ", are you sure to sell them now?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (d == DialogResult.Yes)
                    {
                        selectedClt.BoughtProductList.Remove(selectedPdt);
                        selectedClt.AccountList[0].Balance = selectedClt.AccountList[0].Balance + InterestPdt;
                        using (var context = new Model.Context())
                        {
                            Cursor.Current = Cursors.WaitCursor;                 // waiting animation cursor
                            context.Database.Initialize(force: false);           // connect to db
                            List <Client> clients = context.Clients
                                                    .Include(c => c.AccountList) // get related entities
                                                    .Include(bpl => bpl.BoughtProductList)
                                                    .Include("BoughtProductList.Product")
                                                    .ToList();
                            Client clientInDb = clients.Where(c => c.Id == selectedClt.Id).SingleOrDefault();

                            BoughtProduct productS = context.BoughtProducts.Where(c => c.Id == selectedPdt.Id).SingleOrDefault();
                            context.BoughtProducts.Remove(productS);
                            clientInDb.BoughtProductList.Remove(selectedPdt);
                            clientInDb.AccountList[0].Balance = clientInDb.AccountList[0].Balance + InterestPdt;
                            //Console.Write(context.Clients.Find(VMMain.Client.Id).FirstName);
                            context.SaveChanges();
                        }
                        this.loadClientDetail(selectedClt);
                    }
                }
                else
                {
                    this.VMMain.UIMainForm.genMsgBox("You haven't chosen a product yet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                this.VMMain.UIMainForm.genMsgBox("You haven't chosen a client yet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #4
0
        public CalculatedCartDTO Calculate(CartRequest cart)
        {
            List <BoughtProduct> boughtProducts = new List <BoughtProduct>();

            foreach (var cartItemRequest in cart.CartItems)
            {
                var promotionRules = DomainRegistry.PromotionRepository().GetListByContainsProductId(cartItemRequest.ProductId);
                var boughtProduct  = new BoughtProduct(cartItemRequest.ProductId, cartItemRequest.Quantity, cartItemRequest.UnitPrice, 0, promotionRules, cartItemRequest.SelectedMultiProductsPromotionId);
                boughtProducts.Add(boughtProduct);
            }

            #region 处理单品促销
            foreach (var boughtProduct in boughtProducts.ToList())
            {
                var calculateResult = _mergeSingleProductPromotionForOneProductDomainService.Merge(boughtProduct.ProductId, boughtProduct.DiscountedUnitPrice, boughtProduct.InSingleProductPromotionRules);

                var newBoughtProduct = boughtProduct.ChangeReducePrice(calculateResult);

                boughtProducts.Remove(boughtProduct);
                boughtProducts.Add(newBoughtProduct);
            }
            #endregion

            #region 处理多商品促销&构造DTO模型
            List <CalculatedFullGroupDTO> fullGroupDtos = new List <CalculatedFullGroupDTO>();
            foreach (var groupedPromotoinId in boughtProducts.Where(ent => ent.InMultiProductPromotionRule != null).GroupBy(ent => ((PromotionRule)ent.InMultiProductPromotionRule).PromotoinId))
            {
                var multiProdcutsReducePricePromotion = (IMultiProdcutsReducePricePromotion)groupedPromotoinId.First().InMultiProductPromotionRule;  //暂时只有减金额的多商品促销
                var products = groupedPromotoinId.ToList();

                if (multiProdcutsReducePricePromotion == null)
                {
                    continue;
                }

                var reducePrice = multiProdcutsReducePricePromotion.CalculateReducePrice(products);
                fullGroupDtos.Add(new CalculatedFullGroupDTO
                {
                    CalculatedCartItems      = products.Select(ent => ent.ToDTO()).ToArray(),
                    ReducePrice              = reducePrice,
                    MultiProductsPromotionId = groupedPromotoinId.Key
                });
            }
            #endregion

            return(new CalculatedCartDTO
            {
                CalculatedCartItems = boughtProducts.Where(ent => fullGroupDtos.SelectMany(e => e.CalculatedCartItems).All(e => e.ProductId != ent.ProductId))
                                      .Select(ent => ent.ToDTO()).ToArray(),
                CalculatedFullGroups = fullGroupDtos.ToArray(),
                CartId = cart.CartId
            });
        }
Example #5
0
        public void loadProductDetail(BoughtProduct pdt)
        {
            var listView = View.getListViewProductDetail();

            listView.View = System.Windows.Forms.View.Details;  // set view to details mode sothat it show added item

            // clear the list and readd headers
            listView.Clear();
            listView.Columns.Add("Proprety");
            listView.Columns.Add("Value");

            if (pdt != null)
            {
                // add data in listView
                listView.Items.Add(new ListViewItem(new string[] { "Name", pdt.Product.Name }));
                listView.Items.Add(new ListViewItem(new string[] { "Description", pdt.Product.Description }));
                listView.Items.Add(new ListViewItem(new string[] { "Price", pdt.Price.ToString() }));
                listView.Items.Add(new ListViewItem(new string[] { "Final interest", pdt.FinalInterest.ToString() }));
                listView.Items.Add(new ListViewItem(new string[] { "Start date", pdt.StartDate.ToString("dd/MM/yyyy") }));
                listView.Items.Add(new ListViewItem(new string[] { "End date", pdt.EndDate.ToString("dd/MM/yyyy") }));
                listView.Items.Add(new ListViewItem(new string[] { "Buying date", pdt.BuyingDate.ToString("dd/MM/yyyy") }));
                listView.Items.Add(new ListViewItem(new string[] { "Status", pdt.Product.ProductStatus.ToString() }));

                List <SillInterest> siList = pdt.Product.SillInterests;
                listView.Items.Add(new ListViewItem(new string[] { "", "" }));
                listView.Items.Add(new ListViewItem(new string[] { "Sill(Euro)", "Interest" }));
                foreach (SillInterest si in siList)
                {
                    listView.Items.Add(new ListViewItem(new string[] { si.Sill.ToString(), si.Interest.ToString() }));
                }

                List <TimeInterest> tiList = pdt.Product.TimeInterests;
                listView.Items.Add(new ListViewItem(new string[] { "", "" }));
                listView.Items.Add(new ListViewItem(new string[] { "Time(Month)", "Interest" }));
                foreach (TimeInterest ti in tiList)
                {
                    listView.Items.Add(new ListViewItem(new string[] { ti.Time.ToString(), ti.Interest.ToString() }));
                }

                listView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); // resize columns width
            }
        }
        public async Task AddToSalesHistory(BoughtProduct entity)
        {
            await _context.BoughtProducts.AddAsync(entity);

            await this.ContextSaveChangesAsync();
        }
        public void ChangeReducePriceByMemberPrice_MoreUnitPrice_Failure()
        {
            var boughtProduct = new BoughtProduct("productId", 1, 100, 0, 0, null, null);

            boughtProduct.ChangeReducePriceByMemberPrice(110);
        }
        public void ChangeReducePriceByMemberPrice_LessZero_Failure()
        {
            var boughtProduct = new BoughtProduct("productId", 1, 100, 0, 0, null, null);

            boughtProduct.ChangeReducePriceByMemberPrice(-1);
        }
Example #9
0
 public Task AddToSalesHistory(BoughtProduct entity)
 {
     throw new NotImplementedException();
 }