예제 #1
0
 public DataManager()
 {
     _context = new MangalDBEntities();
 }
        public bool InsertData(DeviationViewModel deviationViewModel)
        {
            bool retVal = false;

            deviationViewModel.CreatedBy = Convert.ToInt32(Session["UserLoginId"]);
            deviationViewModel.UpdatedBy = Convert.ToInt32(Session["UserLoginId"]);

            using (var context = new MangalDBEntities())
            {
                using (DbContextTransaction dbTran = context.Database.BeginTransaction())
                {
                    try
                    {
                        //save  ROI
                        foreach (var p in deviationViewModel.roiDeviationDetailsList)
                        {
                            var roitrn = new Mst_ChildDeviation
                            {
                                ParentId             = 1,
                                ApproveDistanceLimit = 0,
                                MinRange             = p.RoiMinRange,
                                MaxRange             = p.RoiMaxRange,
                                UserCategoryId       = p.RoiUserNo,
                                ThreasoldLimit       = 0,
                                RecordCreatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                                RecordCreated        = DateTime.Now,
                                RecordUpdatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                                RecordUpdated        = DateTime.Now,
                            };
                            context.Mst_ChildDeviation.Add(roitrn);
                        }

                        //Save Distance
                        foreach (var p in deviationViewModel.distanceDeviationDetailsList)
                        {
                            var distancetrn = new Mst_ChildDeviation
                            {
                                ParentId             = 2,
                                ApproveDistanceLimit = deviationViewModel.ApproveDistanceLimit,
                                MinRange             = p.DistanceMinRange,
                                MaxRange             = p.DistanceMaxRange,
                                UserCategoryId       = p.DistanceUserNo,
                                ThreasoldLimit       = 0,
                                RecordCreatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                                RecordCreated        = DateTime.Now,
                                RecordUpdatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                                RecordUpdated        = DateTime.Now,
                            };
                            context.Mst_ChildDeviation.Add(distancetrn);
                        }

                        //Save Distance
                        var ornamenttrn = new Mst_ChildDeviation
                        {
                            ParentId             = 3,
                            ApproveDistanceLimit = 0,
                            MinRange             = 0,
                            MaxRange             = 0,
                            UserCategoryId       = deviationViewModel.OrnamentUserNo,
                            ThreasoldLimit       = 0,
                            RecordCreatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                            RecordCreated        = DateTime.Now,
                            RecordUpdatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                            RecordUpdated        = DateTime.Now,
                        };
                        context.Mst_ChildDeviation.Add(ornamenttrn);

                        //Save Sanction loan amount
                        foreach (var p in deviationViewModel.sanctionDeviationList)
                        {
                            var sanctiontrn = new Mst_ChildDeviation
                            {
                                ParentId             = 4,
                                ApproveDistanceLimit = 0,
                                MinRange             = p.SanctionMinRange,
                                MaxRange             = p.SanctionMaxRange,
                                UserCategoryId       = p.SanctionedUserNo,
                                ThreasoldLimit       = 0,
                                RecordCreatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                                RecordCreated        = DateTime.Now,
                                RecordUpdatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                                RecordUpdated        = DateTime.Now,
                            };
                            context.Mst_ChildDeviation.Add(sanctiontrn);
                        }

                        //Save Sanction loan amount
                        foreach (var p in deviationViewModel.tenureDeviationList)
                        {
                            var sanctiontrn = new Mst_ChildDeviation
                            {
                                ParentId             = 5,
                                ApproveDistanceLimit = 0,
                                MinRange             = p.TenureMinRange,
                                MaxRange             = p.TenureMaxRange,
                                UserCategoryId       = p.TenureUserNo,
                                ThreasoldLimit       = 0,
                                RecordCreatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                                RecordCreated        = DateTime.Now,
                                RecordUpdatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                                RecordUpdated        = DateTime.Now,
                            };
                            context.Mst_ChildDeviation.Add(sanctiontrn);
                        }

                        //save thresold amount
                        var thrsholdntrn = new Mst_ChildDeviation
                        {
                            ParentId             = 6,
                            ApproveDistanceLimit = 0,
                            MinRange             = 0,
                            MaxRange             = 0,
                            UserCategoryId       = 0,
                            ThreasoldLimit       = deviationViewModel.ThresholdLimit,
                            RecordCreatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                            RecordCreated        = DateTime.Now,
                            RecordUpdatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                            RecordUpdated        = DateTime.Now,
                        };
                        context.Mst_ChildDeviation.Add(thrsholdntrn);

                        //Save LTV %
                        foreach (var p in deviationViewModel.lTVDeviationDetailsList)
                        {
                            var sanctiontrn = new Mst_ChildDeviation
                            {
                                ParentId             = 7,
                                ApproveDistanceLimit = 0,
                                MinRange             = p.LTVMinRange,
                                MaxRange             = p.LTVMaxRange,
                                UserCategoryId       = p.LTVUserNo,
                                ThreasoldLimit       = 0,
                                RecordCreatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                                RecordCreated        = DateTime.Now,
                                RecordUpdatedBy      = Convert.ToInt32(Session["UserLoginId"]),
                                RecordUpdated        = DateTime.Now,
                            };
                            context.Mst_ChildDeviation.Add(sanctiontrn);
                        }
                        context.SaveChanges();
                        dbTran.Commit();
                        retVal = true;
                    }
                    catch (DbEntityValidationException ex)
                    {
                        dbTran.Rollback();
                        throw ex;
                    }
                }
            }
            return(retVal);
        }