Пример #1
0
        public static ChargeViewModel ToViewModelPurchase(Mst_Charge charge, ICollection <Mst_ChargeDetails> ChargeTrnList)
        {
            var purchaseviewmodel = new ChargeViewModel
            {
                ChargeName    = charge.Chg_Name,
                ReferenceDate = charge.Chg_ReferenceDate,
                Status        = charge.Chg_Status,
                ID            = charge.Chg_Id,
            };

            IList <ChargeDetailsViewModel> ChargeTrnViewModelList = new List <ChargeDetailsViewModel>();

            foreach (var c in ChargeTrnList)
            {
                var ChargeTrnViewModel = new ChargeDetailsViewModel
                {
                    ID = c.Chgd_Id,
                    LoanAmountGreaterthan = c.Chgd_LoanAmountGreater,
                    LoanAmountLessthan    = c.Chgd_LoanAmountLess,
                    ChargeAmount          = c.Chgd_ChargesAmt,
                    ChargeType            = (short)c.Chgd_ChargeType,
                    ChargeTypeStr         = c.Chgd_ChargeType == 1 ? "Amount" : "Percentage"
                };
                ChargeTrnViewModelList.Add(ChargeTrnViewModel);
            }
            purchaseviewmodel.chargeDetailsCollection = ChargeTrnViewModelList;
            return(purchaseviewmodel);
        }
Пример #2
0
        public bool InsertData(ChargeViewModel chargeViewModel)
        {
            bool retVal = false;

            chargeViewModel.CreatedBy = Convert.ToInt32(Session["UserLoginId"]);
            chargeViewModel.UpdatedBy = Convert.ToInt32(Session["UserLoginId"]);
            Mst_Charge        tblCharge        = new Mst_Charge();
            Mst_ChargeDetails tblChargeDetails = new Mst_ChargeDetails();

            try
            {
                tblCharge.Chg_Name            = chargeViewModel.ChargeName;
                tblCharge.Chg_ReferenceDate   = chargeViewModel.ReferenceDate;
                tblCharge.Chg_Status          = chargeViewModel.Status;
                tblCharge.Chg_RecordCreated   = DateTime.Now;
                tblCharge.Chg_RecordCreatedBy = chargeViewModel.CreatedBy;
                tblCharge.Chg_RecordUpdated   = DateTime.Now;
                tblCharge.Chg_RecordUpdatedBy = chargeViewModel.UpdatedBy;
                dd._context.Mst_Charge.Add(tblCharge);
                dd._context.SaveChanges();

                int PID = dd._context.Mst_Charge.Max(x => x.Chg_Id);

                //save the data in Charge Details table
                foreach (var p in chargeViewModel.chargeDetailsCollection)
                {
                    var chargetrn = new Mst_ChargeDetails
                    {
                        Chgd_ChgRefId          = PID,
                        Chgd_LoanAmountGreater = p.LoanAmountGreaterthan,
                        Chgd_LoanAmountLess    = p.LoanAmountLessthan,
                        Chgd_ChargesAmt        = p.ChargeAmount,
                        Chgd_ChargeType        = p.ChargeType,
                        Chg_RecordCreatedBy    = Convert.ToInt32(Session["UserLoginId"]),
                        Chg_RecordCreated      = DateTime.Now,
                        Chg_RecordUpdatedBy    = Convert.ToInt32(Session["UserLoginId"]),
                        Chg_RecordUpdated      = DateTime.Now,
                    };
                    dd._context.Mst_ChargeDetails.Add(chargetrn);
                    dd._context.SaveChanges();
                }
                retVal = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(retVal);
        }