public MA_COUNTRY Create(SessionInfo sessioninfo, MA_COUNTRY country) { using (EFUnitOfWork unitOfWork = new EFUnitOfWork()) { var checkDuplicate1 = unitOfWork.MA_COUNTRYRepository.All().FirstOrDefault(p => p.LABEL == country.LABEL); if (checkDuplicate1 != null) { throw this.CreateException(new Exception(), "Short name is duplicated"); } //Prepare Country-Limit data MA_COUNTRY_LIMIT ctLimit = new MA_COUNTRY_LIMIT(); ctLimit.ID = Guid.NewGuid(); ctLimit.COUNTRY_ID = country.ID; ctLimit.AMOUNT = 0; ctLimit.EFFECTIVE_DATE = sessioninfo.Process.CurrentDate; ctLimit.EXPIRY_DATE = sessioninfo.Process.CurrentDate; ctLimit.ISACTIVE = true; ctLimit.ISTEMP = false; ctLimit.FLAG_CONTROL = true; ctLimit.LOG.INSERTDATE = DateTime.Now; ctLimit.LOG.INSERTBYUSERID = sessioninfo.CurrentUserId; unitOfWork.MA_COUNTRYRepository.Add(country); unitOfWork.MA_COUNTRY_LIMITRepository.Add(ctLimit); unitOfWork.Commit(); } return(country); }
public static object UpdateCountryLimit(SessionInfo sessioninfo, MA_COUNTRY_LIMIT record) { try { CountryBusiness _countryBusiness = new CountryBusiness(); if (!record.FLAG_CONTROL) { record.AMOUNT = 0; record.EFFECTIVE_DATE = sessioninfo.Process.CurrentDate; record.EXPIRY_DATE = sessioninfo.Process.CurrentDate; } record.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId; record.LOG.MODIFYDATE = DateTime.Now; var updateRecord = _countryBusiness.UpdateCountryLimit(sessioninfo, record); return(new { Result = "OK", Record = updateRecord }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public List <LimitCheckModel> CheckAllCountry(DateTime ProcessingDate, DA_TRN trn, Guid ExcludeID1, Guid ExcludeID2) { CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness(); CountryBusiness _countryBusiness = new CountryBusiness(); List <LimitCheckModel> results = new List <LimitCheckModel>(); LimitCheckModel result; LimitCheckModel temp = new LimitCheckModel(); LimitCheckModel pce = new LimitCheckModel(); MA_COUTERPARTY ctpy = _counterpartyBusiness.GetCounterpartyAll().FirstOrDefault(p => p.ID == trn.CTPY_ID); List <LimitCheckModel> sets = GetCountrySETByCriteria(ProcessingDate, ctpy.COUNTRY_ID, "", ExcludeID1, ExcludeID2); List <LimitCheckModel> pces = GetCountryPCEByCriteria(ProcessingDate, ctpy.COUNTRY_ID, "", ExcludeID1, ExcludeID2); if (pces.Count != 1) { throw new Exception("Invalid country limit data. Please contact administrator"); } else { pce = pces.FirstOrDefault(); } MA_COUNTRY_LIMIT temp_limit = _countryBusiness.GetActiveTempByCountryID(ProcessingDate, trn.MATURITY_DATE.Value, ctpy.COUNTRY_ID); DateTime dateStart = trn.TRADE_DATE.Value; DateTime dateEnd = trn.FLAG_SETTLE.HasValue && trn.FLAG_SETTLE.Value ? trn.DA_TRN_FLOW.Max(p => p.FLOW_DATE).Value : trn.TRADE_DATE.Value; while (dateStart <= dateEnd) { result = new LimitCheckModel(); temp = sets.FirstOrDefault(p => p.FLOW_DATE == dateStart); result.COUNTRY_LABEL = pce.COUNTRY_LABEL; result.COUNTRY_ID = pce.COUNTRY_ID; result.FLAG_CONTROL = pce.FLAG_CONTROL; result.GEN_AMOUNT = pce.GEN_AMOUNT; result.TEMP_AMOUNT = temp_limit != null ? temp_limit.AMOUNT : 0; //result.AMOUNT = pce.AMOUNT + (temp_limit != null ? temp_limit.AMOUNT : 0); result.PROCESSING_DATE = pce.PROCESSING_DATE; result.EXPIRE_DATE = pce.EXPIRE_DATE; result.FLOW_DATE = dateStart; result.ORIGINAL_KK_CONTRIBUTE = pce.ORIGINAL_KK_CONTRIBUTE; if (temp != null) { result.ORIGINAL_KK_CONTRIBUTE = result.ORIGINAL_KK_CONTRIBUTE + temp.ORIGINAL_KK_CONTRIBUTE; } results.Add(result); //if (dateStart.DayOfWeek == DayOfWeek.Friday) // dateStart = dateStart.AddDays(3); //else dateStart = dateStart.AddDays(1); } return(results); }
public MA_COUNTRY_LIMIT UpdateTempCountryLimit(SessionInfo sessioninfo, MA_COUNTRY_LIMIT countryLimit) { using (EFUnitOfWork unitOfWork = new EFUnitOfWork()) { if (countryLimit.EFFECTIVE_DATE < sessioninfo.Process.CurrentDate) { throw this.CreateException(new Exception(), "Effective date cannot be set to past date."); } if (countryLimit.EXPIRY_DATE < sessioninfo.Process.CurrentDate) { throw this.CreateException(new Exception(), "Expiry date cannot be set to past date."); } if (countryLimit.EXPIRY_DATE <= countryLimit.EFFECTIVE_DATE) { throw this.CreateException(new Exception(), "Expiry date must be after effective date."); } var duplicate = unitOfWork.MA_COUNTRY_LIMITRepository.All().FirstOrDefault(p => p.ID != countryLimit.ID && p.ISTEMP == true && p.ISACTIVE == true && p.COUNTRY_ID == countryLimit.COUNTRY_ID && p.EXPIRY_DATE >= countryLimit.EFFECTIVE_DATE); if (duplicate != null) { throw this.CreateException(new Exception(), "Duplicate temp limit info"); } var foundData = unitOfWork.MA_COUNTRY_LIMITRepository.All().FirstOrDefault(p => p.ID == countryLimit.ID); if (foundData == null) { throw this.CreateException(new Exception(), "Data not found!"); } else { LogBusiness logBusiness = new LogBusiness(); var oldRecord = new { AMOUNT = foundData.AMOUNT.ToString("#,##0"), EFFECTIVE_DATE = foundData.EFFECTIVE_DATE, EXPIRE_DATE = foundData.EXPIRY_DATE, ISACTIVE = foundData.ISACTIVE }; var newRecord = new { AMOUNT = countryLimit.AMOUNT.ToString("#,##0"), EFFECTIVE_DATE = countryLimit.EFFECTIVE_DATE, EXPIRE_DATE = countryLimit.EXPIRY_DATE, ISACTIVE = countryLimit.ISACTIVE }; var log = logBusiness.UpdateLogging(sessioninfo, foundData.COUNTRY_ID, LimitLogEvent.TEMP_COUNTRY_LIMIT_AUDIT.ToString(), LookupFactorTables.MA_COUNTRY_LIMIT, oldRecord, newRecord, "Temp Country Limit"); if (log != null) { unitOfWork.DA_LOGGINGRepository.Add(log); } foundData.AMOUNT = countryLimit.AMOUNT; foundData.ISACTIVE = countryLimit.ISACTIVE; foundData.EFFECTIVE_DATE = countryLimit.EFFECTIVE_DATE; foundData.EXPIRY_DATE = countryLimit.EXPIRY_DATE; foundData.LOG.MODIFYBYUSERID = countryLimit.LOG.MODIFYBYUSERID; foundData.LOG.MODIFYDATE = countryLimit.LOG.MODIFYDATE; unitOfWork.Commit(); } } return(countryLimit); }
public MA_COUNTRY_LIMIT GetActiveTempByCountryID(DateTime ProcessingDate, DateTime MaturityDate, Guid ID) { MA_COUNTRY_LIMIT temp_limit = null; using (EFUnitOfWork unitOfWork = new EFUnitOfWork()) { temp_limit = unitOfWork.MA_COUNTRY_LIMITRepository.GetAll().FirstOrDefault(p => p.ISACTIVE == true && p.ISTEMP == true && p.COUNTRY_ID == ID && p.EFFECTIVE_DATE <= ProcessingDate && p.EXPIRY_DATE >= MaturityDate); } return(temp_limit); }
public static object UpdateTempLimit(SessionInfo sessioninfo, MA_COUNTRY_LIMIT record) { try { CountryBusiness _countryBusiness = new CountryBusiness(); record.LOG.MODIFYDATE = DateTime.Now; record.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId; var updateRecord = _countryBusiness.UpdateTempCountryLimit(sessioninfo, record); return(new { Result = "OK", Record = updateRecord }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public static object CreateTempLimit(SessionInfo sessioninfo, MA_COUNTRY_LIMIT record) { try { CountryBusiness _countryBusiness = new CountryBusiness(); record.ID = Guid.NewGuid(); record.ISTEMP = true; record.FLAG_CONTROL = true; record.LOG.INSERTDATE = DateTime.Now; record.LOG.INSERTBYUSERID = sessioninfo.CurrentUserId; var addedRecord = _countryBusiness.CreateTempLimit(sessioninfo, record); return(new { Result = "OK", Record = addedRecord }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public MA_COUNTRY_LIMIT UpdateCountryLimit(SessionInfo sessioninfo, MA_COUNTRY_LIMIT countryLimit) { using (EFUnitOfWork unitOfWork = new EFUnitOfWork()) { if (countryLimit.EXPIRY_DATE < sessioninfo.Process.CurrentDate) { throw this.CreateException(new Exception(), "Expiry date cannot be set to past date."); } var foundData = unitOfWork.MA_COUNTRY_LIMITRepository.All().FirstOrDefault(p => p.ID == countryLimit.ID); if (foundData == null) { throw this.CreateException(new Exception(), "Data not found!"); } else { LogBusiness logBusiness = new LogBusiness(); var oldRecord = new { AMOUNT = foundData.AMOUNT.ToString("#,##0"), EXPIRE_DATE = foundData.EXPIRY_DATE }; var newRecord = new { AMOUNT = countryLimit.AMOUNT.ToString("#,##0"), EXPIRE_DATE = countryLimit.EXPIRY_DATE }; var log = logBusiness.UpdateLogging(sessioninfo, foundData.COUNTRY_ID, LimitLogEvent.COUNTRY_LIMIY_AUDIT.ToString(), LookupFactorTables.MA_COUNTRY, oldRecord, newRecord, "Country Limit"); if (log != null) { unitOfWork.DA_LOGGINGRepository.Add(log); } foundData.AMOUNT = countryLimit.AMOUNT; foundData.FLAG_CONTROL = countryLimit.FLAG_CONTROL; foundData.EXPIRY_DATE = countryLimit.EXPIRY_DATE; foundData.LOG.MODIFYBYUSERID = countryLimit.LOG.MODIFYBYUSERID; foundData.LOG.MODIFYDATE = countryLimit.LOG.MODIFYDATE; unitOfWork.Commit(); } } return(countryLimit); }
public MA_COUNTRY_LIMIT CreateTempLimit(SessionInfo sessioninfo, MA_COUNTRY_LIMIT record) { using (EFUnitOfWork unitOfWork = new EFUnitOfWork()) { if (record.EFFECTIVE_DATE < sessioninfo.Process.CurrentDate) { throw this.CreateException(new Exception(), "Effective date cannot be set to past date."); } if (record.EXPIRY_DATE < sessioninfo.Process.CurrentDate) { throw this.CreateException(new Exception(), "Expiry date cannot be set to past date."); } if (record.EXPIRY_DATE <= record.EFFECTIVE_DATE) { throw this.CreateException(new Exception(), "Expiry date must be after effective date."); } var duplicate = unitOfWork.MA_COUNTRY_LIMITRepository.All().FirstOrDefault(p => p.ISTEMP == true && p.ISACTIVE == true && p.COUNTRY_ID == record.COUNTRY_ID && p.EXPIRY_DATE >= record.EFFECTIVE_DATE); if (duplicate != null) { throw this.CreateException(new Exception(), "Duplicate temp limit info"); } LogBusiness logBusiness = new LogBusiness(); var newRecord = new { AMOUNT = record.AMOUNT, EFFECTIVE_DATE = record.EFFECTIVE_DATE, EXPIRY_DATE = record.EXPIRY_DATE }; unitOfWork.DA_LOGGINGRepository.Add(logBusiness.CreateLogging(sessioninfo, record.COUNTRY_ID, LimitLogEvent.TEMP_COUNTRY_LIMIT_AUDIT.ToString(), LookupFactorTables.MA_COUNTRY_LIMIT, "Temp Country Limit", newRecord)); unitOfWork.MA_COUNTRY_LIMITRepository.Add(record); unitOfWork.Commit(); } return(record); }
public List <LimitCheckModel> GetCountryReport(SessionInfo sessioninfo, string strReportDate, string strCountry, string strSource, string strStatus) { try { DateTime dteReport; LimitCheckBusiness _limitBusiness = new LimitCheckBusiness(); DealBusiness _dealBusiness = new DealBusiness(); CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness(); CountryBusiness _countryBusiness = new CountryBusiness(); Guid guCountryID = Guid.Empty; MA_COUNTRY_LIMIT temp_limit = null; if (String.IsNullOrEmpty(strReportDate)) { throw this.CreateException(new Exception(), "Please input report date."); } else if (!DateTime.TryParseExact(strReportDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteReport)) { throw this.CreateException(new Exception(), "Invalid report date."); } else { dteReport = DateTime.ParseExact(strReportDate, "dd/MM/yyyy", null); } if (_dealBusiness.CountByProcessDate(dteReport) == 0) { throw this.CreateException(new Exception(), "No data for selected report date."); } if (Guid.TryParse(strCountry, out guCountryID)) { guCountryID = Guid.Parse(strCountry); } List <LimitCheckModel> sets = _limitBusiness.GetCountrySETByCriteria(dteReport, guCountryID, strSource, Guid.Empty, Guid.Empty); List <LimitCheckModel> pces = _limitBusiness.GetCountryPCEByCriteria(dteReport, guCountryID, strSource, Guid.Empty, Guid.Empty); var reports = (from report in sets.Union(pces) join pce in pces on report.COUNTRY_ID equals pce.COUNTRY_ID select new LimitCheckModel { COUNTRY_LABEL = report.COUNTRY_LABEL, COUNTRY_ID = report.COUNTRY_ID, FLAG_CONTROL = report.FLAG_CONTROL, GEN_AMOUNT = report.AMOUNT, PROCESSING_DATE = report.PROCESSING_DATE, EXPIRE_DATE = report.EXPIRE_DATE, FLOW_DATE = report.FLOW_DATE, SET_CONTRIBUTE = report.SET_CONTRIBUTE, PCE_CONTRIBUTE = pce.PCE_CONTRIBUTE }).GroupBy(g => new { g.COUNTRY_ID, g.COUNTRY_LABEL, g.FLAG_CONTROL, g.GEN_AMOUNT, g.PROCESSING_DATE, g.EXPIRE_DATE, g.FLOW_DATE, g.PCE_CONTRIBUTE }).Select(s => new LimitCheckModel { COUNTRY_LABEL = s.Key.COUNTRY_LABEL, COUNTRY_ID = s.Key.COUNTRY_ID, FLAG_CONTROL = s.Key.FLAG_CONTROL, GEN_AMOUNT = s.Key.GEN_AMOUNT, PROCESSING_DATE = s.Key.PROCESSING_DATE, EXPIRE_DATE = s.Key.EXPIRE_DATE, FLOW_DATE = s.Key.FLOW_DATE, PCE_CONTRIBUTE = s.Key.PCE_CONTRIBUTE, SET_CONTRIBUTE = s.Sum(x => x.SET_CONTRIBUTE), ORIGINAL_KK_CONTRIBUTE = s.Key.PCE_CONTRIBUTE + s.Sum(y => y.SET_CONTRIBUTE) }).ToList(); foreach (var report in reports) { temp_limit = _countryBusiness.GetActiveTempByCountryID(sessioninfo.Process.CurrentDate, report.FLOW_DATE, report.COUNTRY_ID); if (temp_limit != null) { report.TEMP_AMOUNT = temp_limit.AMOUNT; } } if (strStatus != "") { reports = reports.Where(t => t.STATUS.IndexOf(strStatus, StringComparison.OrdinalIgnoreCase) >= 0).ToList(); } return(reports.OrderBy(p => p.COUNTRY_LABEL).ThenBy(t => t.FLOW_DATE).ToList()); } catch (DataServicesException ex) { throw this.CreateException(ex, null); } }
public static object UpdateCountryLimit(MA_COUNTRY_LIMIT record) { return(CountryUIP.UpdateCountryLimit(SessionInfo, record)); }
public static object CreateTempCountry(MA_COUNTRY_LIMIT record) { return(CountryUIP.CreateTempLimit(SessionInfo, record)); }