示例#1
0
 private void SaveButton_Click(object sender, EventArgs e)
 {
     addMessageLabel.Text       = "";
     saveMessageLabel.Text      = "";
     saveMessageLabel.ForeColor = Color.Red;
     if (listOfSales.Count == 0)
     {
         saveMessageLabel.Text = "Sales item is empty";
         return;
     }
     for (int i = 0; i < listOfSales.Count; i++)
     {
         listOfSales[i].Date = Convert.ToDateTime(listOfSales[i].Date).ToString("yyyy-MM-dd");
         _salesManager.AddSales(listOfSales[i]);
     }
     saveMessageLabel.ForeColor = Color.Green;
     saveMessageLabel.Text      = "Save Successfully";
     listOfSales              = new List <Sales>();
     dateTextBox.Text         = "";
     loyaltyPointTextBox.Text = "<View>";
     customerComboBox.Text    = "-Select-";
     Display();
     grandTotalTextBox.Text      = "<View>";
     discountPercentTextBox.Text = "";
     discountAmountTextBox.Text  = "";
     payableAmountTextBox.Text   = "";
 }
        public ActionResult AddSales(SalesViewModel salesViewModel)
        {
            salesViewModel.CustomerSelectListItems = _customerManager.GetAll().Select(c => new SelectListItem
            {
                Value = c.Id.ToString(),
                Text  = c.CustomerName
            }).ToList();

            ViewBag.Customer = salesViewModel.CustomerSelectListItems;



            salesViewModel.CategorySelectListItems = _categoryManager.GetAll().Select(c => new SelectListItem
            {
                Value = c.Id.ToString(),
                Text  = c.Name
            }).ToList();


            var message = "";

            Sales sales = Mapper.Map <Sales>(salesViewModel);

            if (_salesManager.AddSales(sales))
            {
                ResetLoyaltyPoint(sales.CustomerId, sales.Id);
                message = "Sales Data Save Successfully!!";
            }
            else
            {
                message = "Not Save";
            }

            ViewBag.Category  = salesViewModel.CategorySelectListItems;
            ViewBag.SalesCode = 2019;
            ViewBag.Message   = message;

            return(View(salesViewModel));
        }