public LEFSInterestCodeViewModel GetLEFSInterestCodeById(int?Id)
        {
            LEFSInterestCodeViewModel obj = new LEFSInterestCodeViewModel();

            using (var db = new MainDbContext())
            {
                try
                {
                    Maintenance_LEFSInterestCode objResult = db.Maintenance_LEFSInterestCode.Find(Id);
                    if (objResult != null)
                    {
                        obj.Id              = objResult.Id;
                        obj.InterestCode    = objResult.InterestCode;
                        obj.InterestType    = objResult.InterestType;
                        obj.SubContractType = objResult.SubContractType;
                        obj.EffectiveDate   = objResult.EffectiveDate != null?objResult.EffectiveDate.ToString("dd/MM/yyyy") : "";

                        obj.Description         = objResult.Description;
                        obj.BankRate            = objResult.BankRate;
                        obj.CoyRate             = objResult.CoyRate;
                        obj.RiskSpring          = objResult.RiskSpring;
                        obj.RiskEthoz           = objResult.RiskEthoz;
                        obj.RepaymentPeriodFrom = objResult.RepaymentPeriodFrom;
                        obj.RepaymentPeriodTo   = objResult.RepaymentPeriodTo;
                        obj.Remarks             = objResult.Remarks;
                        obj.CreatedBy           = objResult.CreatedBy;
                        obj.CreatedDate         = objResult.CreatedDate != null?Convert.ToDateTime(objResult.CreatedDate).ToString("dd/MM/yyyy") : "";

                        obj.UpdatedBy   = objResult.UpdatedBy;
                        obj.UpdatedDate = objResult.UpdatedDate != null?Convert.ToDateTime(objResult.UpdatedDate).ToString("dd/MM/yyyy") : "";

                        obj.ActiveStatus        = objResult.Status;
                        obj.DeactivationRemarks = objResult.DeactivationRemarks;
                    }
                }
                catch (Exception ex)
                {
                    var result = new ResultViewModel();
                    glog.Error("GetLEFSInterestCodeById Exception: " + ex.Message);
                    result.Status  = 0;
                    result.Message = "Please contact MIS, error: " + ex.Message;
                }
            }
            return(obj);
        }
Пример #2
0
        // GET: LEFSInterestCode
        public ActionResult LEFSInterestCodeNew(string SubMenuId, int?InterestCodeId, bool IsEnable = true)
        {
            Session.Clear();
            var db = new MainDbContext();

            ViewBag.IsPrePostContrat = 0;
            LEFSInterestCodeViewModel obj = new LEFSInterestCodeViewModel();

            #region Check Whether LEFS Interest Code in active Pre/Posted contract. If yes, not allowed to modify.
            if (InterestCodeId > 0)
            {
                obj = _clsLEFSInterestCode.GetLEFSInterestCodeById(InterestCodeId);
                if (obj != null)
                {
                    var contractQuery =
                        (from pre in db.PreContract_Master
                         select new { pre.LEFSInterestCode, pre.Status }
                        ).Where(x => x.LEFSInterestCode != null && x.Status != null && x.Status.ToLower() != "x")
                        .Union
                            (from post in db.Contract_Master
                            select new { post.LEFSInterestCode, post.Status }).Where(x => x.LEFSInterestCode != null && x.Status != null && x.Status.ToLower() != "x");

                    int count = contractQuery.Where(x => x.LEFSInterestCode.ToLower().Equals(obj.InterestCode.ToLower())).Count();
                    ViewBag.IsPrePostContrat = count;
                    TempData.Keep("SubMenuId");
                }
            }
            else
            {
                #region Check UserGroup when user direct key in URL
                if (!(_clsGlobal.CheckUserGroup(((ClaimsIdentity)User.Identity).FindFirst("UserGroupCode").Value, Convert.ToInt16(SubMenuId))))
                {
                    ViewData["Message"] = "You Have No Access Rights For This Module!, error: Invalid Access Rights";
                }
                #endregion  Check UserGroup when user direct key in URL
            }
            #endregion

            List <SelectListItem> lstInterestType = _clsGlobal.GetListOfValue("LEFS_INTEREST_TYPE", "", "O", "", "");
            ViewData["getType"] = lstInterestType;

            var lstContractType = _clsGlobal.GetListOfValue("SUB_CONTRACT_TYPE", "CT-1004", "O", "", "");
            ViewData["getContract"] = lstContractType;

            List <SelectListItem> lstStatus = _clsGlobal.GetListOfValue("GENERAL_STATUS", "", "", "", "");
            ViewData["status"] = lstStatus;

            List <SelectListItem> lstRepaymentPeriod = new List <SelectListItem>();

            lstRepaymentPeriod.Add(new SelectListItem {
                Text = "--Select--", Value = ""
            });
            for (int i = 1; i <= 20; i++)
            {
                lstRepaymentPeriod.Add(new SelectListItem {
                    Text = i.ToString(), Value = i.ToString()
                });
            }
            ViewBag.RepaymentPeriodFrom = new SelectList(lstRepaymentPeriod, "Value", "Text", obj.RepaymentPeriodFrom);
            ViewBag.RepaymentPeriodTo   = new SelectList(lstRepaymentPeriod, "Value", "Text", obj.RepaymentPeriodTo);

            ViewBag.IsEnable = IsEnable;

            return(View(obj));
        }
        public ResultViewModel InsertLEFSInterestCode(LEFSInterestCodeViewModel Model, string UserName)
        {
            string userMail = "";

            glog.Debug("InsertLEFSInterestCode: Entry");
            var result = new ResultViewModel();

            using (var db = new MainDbContext())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        Maintenance_LEFSInterestCode InterestCode = new Maintenance_LEFSInterestCode();
                        var isInterestCode = db.Maintenance_LEFSInterestCode.Any(x => x.InterestCode == Model.InterestCode && x.Id != Model.Id);
                        if (isInterestCode)
                        {
                            result.Status  = 2;
                            result.Message = " Interest code is already exist!";
                            return(result);
                        }
                        userMail = db.Sys_Users.FirstOrDefault(x => x.Name == UserName).Email;

                        InterestCode.InterestCode        = Model.InterestCode;
                        InterestCode.InterestType        = Model.InterestType;
                        InterestCode.SubContractType     = Model.SubContractType;
                        InterestCode.EffectiveDate       = Convert.ToDateTime(Model.EffectiveDate);
                        InterestCode.Description         = Model.Description;
                        InterestCode.BankRate            = Model.BankRate;
                        InterestCode.CoyRate             = Model.CoyRate;
                        InterestCode.RiskSpring          = Model.RiskSpring;
                        InterestCode.RiskEthoz           = Model.RiskEthoz;
                        InterestCode.RepaymentPeriodFrom = Model.RepaymentPeriodFrom;
                        InterestCode.RepaymentPeriodTo   = Model.RepaymentPeriodTo;
                        InterestCode.Remarks             = Model.Remarks;

                        if (Model.Id > 0)
                        {
                            var data = GetLEFSInterestCodeById(Model.Id);
                            InterestCode.UpdatedBy   = userMail;
                            InterestCode.UpdatedDate = DateTime.Now;
                            InterestCode.Status      = data.ActiveStatus;
                            InterestCode.CreatedBy   = data.CreatedBy;
                            InterestCode.CreatedDate = !string.IsNullOrEmpty(data.CreatedDate) ? DateTime.ParseExact(data.CreatedDate, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null;
                        }
                        else
                        {
                            InterestCode.Status      = "O";
                            InterestCode.CreatedBy   = userMail;
                            InterestCode.CreatedDate = DateTime.Now;
                        }
                        db.Maintenance_LEFSInterestCode.Add(InterestCode);
                        if (Model.Id > 0)
                        {
                            InterestCode.Id = Model.Id;
                            db.Entry(InterestCode).State = System.Data.Entity.EntityState.Modified;
                        }
                        else
                        {
                            db.Entry(InterestCode).State = System.Data.Entity.EntityState.Added;
                        }
                        var id = db.SaveChanges();

                        transaction.Commit();
                        if (id > 0)
                        {
                            result.Status  = 1;
                            result.Message = "New LEFS interest code saved successfully.";
                        }
                        else
                        {
                            result.Status  = 0;
                            result.Message = "Some error occured when saving new LEFS interest code";
                        }
                    }
                    catch (Exception ex)
                    {
                        glog.Error("InsertLEFSInterestCode Exception: " + ex.Message);
                        result.Status  = 0;
                        result.Message = "Please contact MIS, error: " + ex.Message;
                        transaction.Rollback();
                    }
                    finally
                    {
                        transaction.Dispose();
                    }
                    glog.Debug("InsertLEFSInterestCode: Exit");
                    return(result);
                }
            }
        }