private float BillCalculator(CustomerBill cb)
        {
            float totalBill = 0;

            foreach (Perform perform in cb.performList)
            {
                switch (perform.performType)
                {
                case PerformType.Comedy:
                    totalBill += 30000;
                    if (perform.audience - 20 > 0)
                    {
                        totalBill += (perform.audience - 20) * 500;
                    }
                    break;

                case PerformType.Tragedy:
                    totalBill += 40000;
                    if (perform.audience - 30 > 0)
                    {
                        totalBill += (perform.audience - 30) * 1000;
                    }
                    break;

                default:
                    Console.WriteLine("Unregistered performance");
                    break;
                }
            }
            return(totalBill);
        }
Esempio n. 2
0
        public static CustomerBill TableToCustomerBill(MySqlDataReader row)
        {
            CustomerBill obj = new CustomerBill();
            int          i   = 0;

            while (row.Read())
            {
                if (i == 0)
                {
                    obj.Id = row["id"].ToString();
                    obj.CustomerNickName = row["customer_nick_name"].ToString();
                    obj.Total            = Convert.ToInt32(row["total"]);
                    obj.TotalPrice       = Convert.ToDecimal(row["total_price"]);
                    obj.GoodsList        = new List <CustomerGoods>();
                    i++;
                }
                CustomerGoods goods = new CustomerGoods();
                goods.GoodsName     = row["goods_name"].ToString();
                goods.Quantity      = Convert.ToInt32(row["quantity"]);
                goods.OutUnitPrice  = Convert.ToDecimal(row["out_unit_price"]);
                goods.OutTotalPrice = Convert.ToDecimal(row["out_total_price"]);
                obj.GoodsList.Add(goods);
            }
            return(obj);
        }
Esempio n. 3
0
 public ActionResult <CustomerBill> Post([FromBody] CustomerBill customerBill)
 {
     try
     {
         var clientEntity = _customerBillService.Insert(customerBill);
         //return Ok("success");
         return(Ok(clientEntity));
     }
     catch
     {
         return(new StatusCodeResult(500));
     }
 }
Esempio n. 4
0
 public void SaveCustomerBill(CustomerBill customerBill)
 {
     customerBill.TimeStamp = DateHelper.GetDateNowString_Sortable();
     if (customerBill.Id == 0)
     {
         context.CustomerBills.Add(customerBill);
         context.SaveChanges();
     }
     else
     {
         context.CustomerBills.Attach(customerBill);
         context.Entry(customerBill).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
        /// <summary>
        /// The method BillCalculator will return a float value according to business rules.
        /// </summary>
        /// <param name="customerBill"></param>
        /// <returns></returns>
        public CustomerBill Insert(CustomerBill customerBill)
        {
            CustomerBill customerBillUpdated = customerBill;

            try
            {
                customerBillUpdated.billValue = BillCalculator(customerBill);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught.", e);
            }

            return(_customerBillRepository.Insert(customerBill));
        }
Esempio n. 6
0
        public void SaveCustomerBillBreakupList(CustomerBill customerBill, List <ProductInCart> productListInCart)
        {
            using (var dbContextTransaction = context.Database.BeginTransaction())
            {
                try
                {
                    SaveCustomerBill(customerBill);
                    foreach (ProductInCart productInCart in productListInCart)
                    {
                        CustomerBillBreakup customerBillBreakup = new CustomerBillBreakup();

                        customerBillBreakup.CustomerBillId      = customerBill.Id;
                        customerBillBreakup.DealerBillBreakupId = productInCart.DealerBillBreakupId;
                        customerBillBreakup.ProductId           = productInCart.ProductId;
                        customerBillBreakup.TotalAmount         = productInCart.SellingAmount;
                        customerBillBreakup.TotalQuantity       = productInCart.SellingQuantity;
                        customerBillBreakup.UnitPrice           = productInCart.SellingUnitPrice;
                        customerBillBreakup.TotalBoxes          = productInCart.TotalBoxes;
                        customerBillBreakup.QuantityInBox       = productInCart.QuantityInBox;
                        SaveCustomerBillBreakup(customerBillBreakup);

                        // Reduce available quantity
                        DealerBillBreakup dealerBillBreakup = context.DealerBillBreakups.Find(customerBillBreakup.DealerBillBreakupId);
                        if (dealerBillBreakup == null)
                        {
                            dbContextTransaction.Rollback();
                            throw new Exception("Dealer bill breakup is not found");
                        }
                        else if (dealerBillBreakup.AvailableQuantity < customerBillBreakup.TotalQuantity)
                        {
                            dbContextTransaction.Rollback();
                            throw new Exception("Available quantity is less than sold quantity");
                        }
                        dealerBillBreakup.AvailableQuantity = dealerBillBreakup.AvailableQuantity - customerBillBreakup.TotalQuantity;
                        SaveDealerBillBreakup(dealerBillBreakup);
                    }

                    dbContextTransaction.Commit();
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    throw new Exception("Billing failed" + ex.Message);
                }
            }
        }
        public static ICustomerBill CreateCustomerBillObject()
        {
            ICustomerBill objCustomerBill = new CustomerBill();

            return(objCustomerBill);
        }
Esempio n. 8
0
 public CustomerBill Insert(CustomerBill customeBill)
 {
     return(_customerBillBusiness.Insert(customeBill));
 }
Esempio n. 9
0
 public string ToFileLine() // CSV, no formatting
 {
     return(CustomerName + ", " + CustomerBill.ToString() + "," + AccountNumber + ", " + CustomerType);
 }
Esempio n. 10
0
 // redefine (override) method ToString that was inheritted from object class
 public override string ToString()
 {
     return(CustomerName + ": " + CustomerBill.ToString() + "," + AccountNumber + ", " + CustomerType);
 }
Esempio n. 11
0
        public ActionResult <string> CompletePayment([FromBody] PaymentDetails paymentDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var customer = _accountService.FindCustomerByUserName(paymentDetails.CustomerUserName);

            var order = new Orders()
            {
                Customer    = customer,
                DateCreated = paymentDetails.Date,
                TotalAmount = paymentDetails.Total
            };

            var orderResult = _paymentService.PlaceOrder(order);

            var itemResult = from cartItem in paymentDetails.Cart
                             group cartItem by cartItem.Id into g
                             let count = g.Count()
                                         select new { Value = g.Key, Count = count };

            foreach (var i in itemResult)
            {
                var item = paymentDetails.Cart.FirstOrDefault(c => c.Id == i.Value);

                var orderDetails = new OrderDetails()
                {
                    OrderId  = orderResult.Id,
                    BookId   = i.Value,
                    Quantity = i.Count,
                    UnitCost = item.Price
                };

                var orderDetailsResult = _paymentService.PlaceOrderDetails(orderDetails);
            }

            var payment = new Payments()
            {
                CustomerName  = customer.Name,
                PaymentMethod = paymentDetails.PaymentMethod,
                PaymentAmount = paymentDetails.Total,
                PaymentDate   = paymentDetails.Date,
                OrderID       = orderResult.Id
            };

            var paymentResult = _paymentService.ConfirmPayment(payment);

            foreach (var i in itemResult)
            {
                var item = _productService.FindBookByID(i.Value);

                var updatedStockResult = _productService.DecreaseBookStock(item, i.Count);
            }

            List <ItemDetails> itemDetailsList = new List <ItemDetails>();

            foreach (var i in itemResult)
            {
                var item = paymentDetails.Cart.FirstOrDefault(c => c.Id == i.Value);

                var itemDetail = new ItemDetails()
                {
                    Name     = item.Name,
                    Quantity = i.Count,
                    UnitCost = item.Price
                };

                itemDetailsList.Add(itemDetail);
            }

            var customerBill = new CustomerBill()
            {
                Payment        = payment,
                ItemDetailList = itemDetailsList
            };

            var mailRequest = new MailRequest()
            {
                ToEmail = customer.Email,
                Subject = "Your Payment Confirmation",
                Bill    = customerBill
            };

            // Passing to the Email service.
            _emailService.SendEmailAsync(mailRequest);

            return("Purchase is Successfull.");
        }