public CreditCategory Get(int id)
        {
            CreditCategory category = new CreditCategory();

            category = auctionContext.CreditCategories.Where(a => a.iCreditCategoryID == id).FirstOrDefault();
            return(category);
        }
        private CreditCategory ParserAddCategory(CreditCategoryModel category)
        {
            CreditCategory mCategory = new CreditCategory();

            if (category != null)
            {
                mCategory.iCreditCategoryID = category.iCreditCategoryID;
                mCategory.strCategory       = category.strCategory;
                mCategory.iDays             = category.iDays;
            }
            return(mCategory);
        }
Пример #3
0
        public RepaymentChartViewModel GetRepaymentChartViewModel(Guid id)
        {
            RepaymentChartViewModel repaymentChartViewModel = new RepaymentChartViewModel();
            CreditApplication       creditApplication       = unitOfWork.GetRepository <CreditApplication>().GetById(id);

            if (creditApplication.Client.ClientGroup == ClientGroup.PrivatePerson)
            {
                LegalPerson client = unitOfWork.GetRepository <LegalPerson>().GetById(creditApplication.ClientId);
                repaymentChartViewModel.ClientName = client.FirstName + " " + client.LastName;
            }
            else
            {
                repaymentChartViewModel.ClientName = unitOfWork.GetRepository <JuridicalPerson>().GetById(creditApplication.ClientId).Name;
            }

            CreditCategory creditCategory = creditApplication.CreditCategory;
            List <string>  keys           = new List <string>();
            List <double>  values         = new List <double>();
            double         percent        = creditCategory.Rate;
            double         money          = Convert.ToDouble(creditCategory.MaxAmount);
            int            months         = creditCategory.Span;

            if (creditCategory.RepaymentScheme == RepaymentScheme.Annuity)
            {
                double monthlyPercent = percent / 100 / 12;
                double monthlyPayment = money * monthlyPercent / (1 - Math.Pow(1 + monthlyPercent, (-1) * months));
                for (int i = 0; i < months; i++)
                {
                    values.Add(monthlyPayment);
                }
            }
            else
            {
                DateTime date            = creditApplication.CompleteDate.Value;
                double   fixedPayment    = money / months;
                double   variablePayment = 0;
                for (int i = 0; i < months; i++)
                {
                    variablePayment = money * percent / 100 * 31 / 365;
                    money          -= fixedPayment;
                    values.Add(fixedPayment + variablePayment);
                }
            }
            keys = GetKeys(creditApplication.CompleteDate.Value, months);
            repaymentChartViewModel.Keys   = JsonConvert.SerializeObject(keys.ToArray());
            repaymentChartViewModel.Values = JsonConvert.SerializeObject(values.ToArray());
            return(repaymentChartViewModel);
        }
        public bool SaveEdit(CreditCategory category)
        {
            bool status = false;

            if (category.iCreditCategoryID > 0)
            {
                //Edit Existing Record
                var UpdateCategory = auctionContext.CreditCategories.Where(a => a.iCreditCategoryID == category.iCreditCategoryID).FirstOrDefault();
                if (UpdateCategory != null)
                {
                    UpdateCategory.strCategory = category.strCategory;
                    UpdateCategory.iDays       = category.iDays;
                }
            }
            else
            {
                //Save
                auctionContext.CreditCategories.Add(category);
            }
            auctionContext.SaveChanges();
            status = true;
            return(status);
        }