Beispiel #1
0
        public static object GetCountryOptions(SessionInfo sessioninfo)
        {
            try
            {
                CountryBusiness _countryBusiness = new CountryBusiness();
                //Get data from database
                var countries = _countryBusiness.GetCountryAll()
                                .OrderBy(p => p.LABEL)
                                .Select(c => new { DisplayText = c.LABEL, Value = c.ID });

                //Return result to jTable
                return(new { Result = "OK", Options = countries });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Beispiel #2
0
        public List <LimitAuditReportModel> GetLimitAuditReport(SessionInfo sessionInfo, string strLogDatefrom, string strLogDateto, string strCtpy, string strCountry, string strEvent)
        {
            try
            {
                DateTime             dteReportfrom;
                DateTime             dteReportto;
                Guid                 guCtpyID              = Guid.Empty;
                Guid                 guCountryID           = Guid.Empty;
                LogBusiness          _logBusiness          = new LogBusiness();
                CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
                CountryBusiness      _countryBusiness      = new CountryBusiness();
                UserBusiness         _userBusiness         = new UserBusiness();

                var log = _logBusiness.GetLogAll().Where(l => l.EVENT == LimitLogEvent.LIMIT_AUDIT.ToString() ||
                                                         l.EVENT == LimitLogEvent.TEMP_LIMIT_AUDIT.ToString() ||
                                                         l.EVENT == LimitLogEvent.COUNTRY_LIMIY_AUDIT.ToString() ||
                                                         l.EVENT == LimitLogEvent.TEMP_COUNTRY_LIMIT_AUDIT.ToString()).AsQueryable();

                var ctpyLimit = _counterpartyBusiness.GetCounterpartyLimitAll().AsQueryable();
                var ctpys     = _counterpartyBusiness.GetCounterpartyAll().AsQueryable();
                var countrys  = _countryBusiness.GetCountryAll().AsQueryable();
                var users     = _userBusiness.GetAll().AsQueryable();

                if (String.IsNullOrEmpty(strLogDatefrom))
                {
                    throw this.CreateException(new Exception(), "Please input start log date.");
                }
                else if (!DateTime.TryParseExact(strLogDatefrom, "dd/MM/yyyy", null, DateTimeStyles.None, out dteReportfrom))
                {
                    throw this.CreateException(new Exception(), "Invalid start log date.");
                }
                else
                {
                    dteReportfrom = DateTime.ParseExact(strLogDatefrom, "dd/MM/yyyy", null);
                }

                if (String.IsNullOrEmpty(strLogDateto))
                {
                    throw this.CreateException(new Exception(), "Please input end log date.");
                }
                else if (!DateTime.TryParseExact(strLogDateto, "dd/MM/yyyy", null, DateTimeStyles.None, out dteReportto))
                {
                    throw this.CreateException(new Exception(), "Invalid end log date.");
                }
                else
                {
                    dteReportto = DateTime.ParseExact(strLogDateto, "dd/MM/yyyy", null);
                }
                if (dteReportto < dteReportfrom)
                {
                    throw this.CreateException(new Exception(), "Start log date must before end log date.");
                }

                var limits = from limit in ctpyLimit
                             join ctpy in ctpys on limit.CTPY_ID equals ctpy.ID
                             select new
                {
                    LIMIT_ID = limit.ID,
                    CTPY_ID  = ctpy.ID,
                    SNAME    = ctpy.SNAME,
                    LIMIT    = limit.MA_LIMIT.LABEL
                };

                log = log.Where(l => l.LOG_DATE.Date >= dteReportfrom.Date && l.LOG_DATE.Date <= dteReportto.Date);

                if (strEvent != "-1")
                {
                    log = log.Where(p => p.EVENT == strEvent);
                }

                var limitAudits = from l in log
                                  join user in users on l.LOG.INSERTBYUSERID equals user.ID
                                  join c in limits on l.RECORD_ID equals c.LIMIT_ID into templimit
                                  from sublimit in templimit.DefaultIfEmpty()
                                  join country in countrys on l.RECORD_ID equals country.ID into tempcountry
                                  from subcountry in tempcountry.DefaultIfEmpty()
                                  orderby l.LOG_DATE
                                  select new LimitAuditReportModel
                {
                    ENTITY       = sublimit != null ? sublimit.SNAME : subcountry != null ? subcountry.LABEL : "",
                    ENTITY_ID    = sublimit != null ? sublimit.CTPY_ID : (subcountry != null ? subcountry.ID : Guid.Empty),
                    LIMIT        = (l.EVENT.Contains("TEMP") ? "TEMP-" : "") + (sublimit != null ? sublimit.LIMIT : "COUNTRY-LIMIT"),            //sublimit != null ? sublimit.LIMIT : "Country Limit",
                    USER         = user.USERCODE,
                    LOG_DATE     = l.LOG_DATE,
                    LOG_DATE_STR = l.LOG_DATE.ToString("dd-MMM-yyyy HH:mm"),
                    DETAIL       = l.LOG_DETAIL
                };

                if (Guid.TryParse(strCtpy, out guCtpyID))
                {
                    guCtpyID    = Guid.Parse(strCtpy);
                    limitAudits = limitAudits.Where(p => p.ENTITY_ID == guCtpyID);
                }

                if (Guid.TryParse(strCountry, out guCountryID))
                {
                    guCountryID = Guid.Parse(strCountry);
                    limitAudits = limitAudits.Where(t => t.ENTITY_ID == guCountryID);
                }

                return(limitAudits.ToList());
            }
            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }