public async Task <int> GetDatabaseVersion() { var databaseVersion = await _systemSettingRepository.Get("DatabaseVersion"); if (databaseVersion == null) { throw new NotFoundException("Database version not found."); } return(Convert.ToInt32(databaseVersion.Setting)); }
public SystemSetting GetEnableOrDisable(bool enable = true, bool isCache = true) { if (!isCache) { return(_systemSettingRepository.Get(x => x.Status == (enable ? (int)Status.Enable : (int)Status.Disable))); } var sbKey = new StringBuilder(); sbKey.AppendFormat(CacheKey, "GetEnableOrDisable"); sbKey.Append(enable); var key = sbKey.ToString(); var systemSetting = _cacheManager.Get <SystemSetting>(key); if (systemSetting == null) { systemSetting = _systemSettingRepository.Get(x => x.Status == (enable ? (int)Status.Enable : (int)Status.Disable)); _cacheManager.Put(key, systemSetting); } return(systemSetting); }
public async Task <IEnumerable <BillModel> > GenerateChargeBills() { var hasSetting = int.TryParse((await _settingRepository.Get(SystemSettings.BillPaymentPeriodLength)).Setting, out int paymentPeriodLength); if (!hasSetting) { throw new LogicException("Bill payment period length not defined."); } var billableStudents = (await _studentChargeRepository.GetOutstanding()).GroupBy(sc => sc.StudentId); var generatedBills = new List <Bill>(); foreach (var billableStudent in billableStudents) { var bill = new Bill { CreatedDate = DateTime.Now, StudentId = billableStudent.Key, DueDate = DateTime.Today.AddMonths(paymentPeriodLength) }; foreach (var charge in billableStudent) { bill.BillCharges.Add(new BillCharge { ChargeId = charge.ChargeId, GrossAmount = charge.Charge.Amount }); var chargeInDb = await _studentChargeRepository.GetByIdWithTracking(charge.ChargeId); chargeInDb.Recurrences--; } var studentDiscounts = await _studentDiscountRepository.GetByStudent(billableStudent.Key); foreach (var studentDiscount in studentDiscounts) { var applicableChargeIds = (await _chargeDiscountRepository.GetByDiscount(studentDiscount.DiscountId)).Select(x => x.ChargeId); if (bill.BillCharges.Any(c => applicableChargeIds.Contains(c.ChargeId))) { bill.BillDiscounts.Add(new BillDiscount { DiscountId = studentDiscount.DiscountId, Amount = studentDiscount.Discount.Amount, Percentage = studentDiscount.Discount.Percentage }); } } _billRepository.Create(bill); generatedBills.Add(bill); } await _billRepository.SaveChanges(); return(generatedBills.Select(BusinessMapper.Map <BillModel>)); }