示例#1
0
        public int Insert(Services.BillConsumption.BillConsumptionAddViewModel model, ref string ErrorMsg)
        {
            int ID = 0;

            db = new SqlConnection(ConfigurationManager.ConnectionStrings["cnConsumption"].ConnectionString);

            decimal BillAmount = model.BillHeader.Consumption * model.BillHeader.Rate;
            string  sql        = " INSERT INTO tblBillConsumption(ContractNo,InvoiceNo,CurrentReadingPeriodFrom,CurrentReadingPeriodTo," +
                                 " CurrentReadingDate,CurrentReading,Consumption,Rate,ServiceCharges,BillAmount,PaidAmount) " +
                                 " VALUES (@ContractNo,@InvoiceNo,@CurrentReadingPeriodFrom,@CurrentReadingPeriodTo," +
                                 " @CurrentReadingDate,@CurrentReading,@Consumption,@Rate,@ServiceCharges,@BillAmount,@PaidAmount)" +
                                 " Select Cast(SCOPE_IDENTITY() AS int)";

            try
            {
                ID = db.Query <int>(sql, new
                {
                    model.CustomerDetail.ContractNo,
                    model.BillHeader.InvoiceNo,
                    model.BillHeader.CurrentReadingPeriodFrom,
                    model.BillHeader.CurrentReadingPeriodTo,
                    model.BillHeader.CurrentReadingDate,

                    model.BillHeader.CurrentReading,
                    model.BillHeader.Consumption,
                    model.BillHeader.Rate,
                    model.BillHeader.ServiceCharges,
                    BillAmount,
                    model.BillHeader.PaidAmount,
                }).SingleOrDefault();
            }
            catch (Exception e)
            {
                if (e.Message.IndexOf("IX_tblItem-Name") > 0)
                {
                    ErrorMsg = "Item Already Exist....";
                }
                else
                {
                    ErrorMsg = e.Message;
                }

                db.Close();
                return(0);
            }

            return(ID);
        }
 public int Insert(Services.BillConsumption.BillConsumptionAddViewModel model, ref string ErrorMsg)
 {
     IRepository = new BillConsumptionRepository();
     return(IRepository.Insert(model, ref ErrorMsg));
 }