Esempio n. 1
0
        public ActionResult CreateNewBill(FormCollection bill_)
        {
            var billID = bill_["hiddenID"];

            //parse ints
            int.TryParse(billID, out _billId);
            int.TryParse(bill_["collectedBill.GFS_CodeId"], out gfs_id);

            decimal.TryParse(bill_["collectedBill.Amount"], out _amount);
            decimal.TryParse(bill_["collectedBill.ExchangeRate"], out exchangeRate);


            var newBill  = new CollectedBill();
            var gfsCodes = DB.GFSCodes.ToList();


            if ((gfs_id != null) && (gfs_id > 0))
            {
                gCode = DB.GFSCodes.SingleOrDefault(c => c.id == gfs_id).CodeNumber;
            }
            else
            {
                gCode = "Non.";
            }


            if ((_billId == null) || (_billId <= 0))
            {
                //Add New Bill To DB

                newBill.PayerName    = bill_["collectedBill.PayerName"];
                newBill.PhoneNumber  = bill_["collectedBill.PhoneNumber"];
                newBill.CreatedDate  = DateTime.Now;
                newBill.BillDate     = DateTime.Parse(bill_["collectedBill.BillDate"]);
                newBill.GFSCodeStr   = gCode;
                newBill.GFS_CodeId   = gfs_id;
                newBill.PaymentCode  = bill_["collectedBill.PaymentCode"];
                newBill.Description  = bill_["collectedBill.Description"];
                newBill.Amount       = _amount;
                newBill.ExchangeRate = exchangeRate;
                newBill.TotalAmount  = _amount * exchangeRate;
                var a = 0;
                DB.CollectedBills.Add(newBill);
            }
            else
            {
                int dbID;
                int.TryParse(billID, out dbID);

                int.TryParse(bill_["collectedBill.GFS_CodeId"], out gfEdit);

                decimal.TryParse(bill_["collectedBill.Amount"], out _amount);
                decimal.TryParse(bill_["collectedBill.ExchangeRate"], out exchangeRate);

                //Convert Bill ID to Int

                var bill = DB.CollectedBills.Single(m => m.id == dbID);

                bill.PayerName   = bill_["collectedBill.PayerName"];
                bill.PhoneNumber = bill_["collectedBill.PhoneNumber"];

                if ((gfEdit != null) && (gfEdit > 0))
                {
                    gfCode_ = DB.GFSCodes.SingleOrDefault(c => c.id == gfEdit).CodeNumber;
                }
                else
                {
                    gfCode_ = "Nill";
                }



                bill.CreatedDate  = DateTime.Now;
                bill.BillDate     = DateTime.Parse(bill_["collectedBill.BillDate"]);
                bill.GFS_CodeId   = gfEdit;
                bill.GFSCodeStr   = gfCode_;
                bill.PaymentCode  = bill_["collectedBill.PaymentCode"];
                bill.Description  = bill_["collectedBill.Description"];
                bill.ControlNo    = bill_["collectedBill.ControlNo"];
                bill.Amount       = _amount;
                bill.ExchangeRate = exchangeRate;
                bill.TotalAmount  = _amount * exchangeRate;
            }
            DB.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
 public CollectedBillViewModel()
 {
     collectedBill = new CollectedBill();
 }