public MA_INSTRUMENT GetByID(SessionInfo sessioninfo, Guid guID)
        {
            try
            {
                MA_INSTRUMENT instrument = null;
                using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
                {
                    instrument = unitOfWork.MA_INSTRUMENTRepository.GetByID(guID);
                }

                //if (instruments.Count == 1)
                //{
                //    return instruments[0];
                //}
                //else
                //{
                //    throw this.CreateException(new Exception() , "Found multiple instruments with label " + strLabel);
                //}
                return instrument;
            }
            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
        public List<MA_INSTRUMENT> GetBondsByFilter(SessionInfo sessioninfo, string label, string sorting)
        {
            try
            {
                IEnumerable<MA_INSTRUMENT> sortedRecords;
                using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
                {
                    var query = unitOfWork.MA_INSTRUMENTRepository.GetAll().Where(p => p.MA_PRODUCT.LABEL.Equals(ProductCode.BOND.ToString())).AsQueryable();
                    //Filters
                    if (!string.IsNullOrEmpty(label))
                    {
                        query = query.Where(p => p.LABEL.IndexOf(label, StringComparison.OrdinalIgnoreCase) >= 0);
                    }

                    //Sorting
                    string[] sortsp = sorting.Split(' ');
                    IQueryable<MA_INSTRUMENT> orderedRecords = query.OrderBy(sortsp[0], sortsp[1]);
                    sortedRecords = orderedRecords.ToList();
                }
                //Return result to jTable
                return sortedRecords.ToList();

            }
            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
        public List<MA_PROFILE_FUNCTIONAL> GetProfileFunctionByFilter(SessionInfo sessioninfo,string strprofile,string strfunction,string sorting)
        {
            try
            {
                IEnumerable<MA_PROFILE_FUNCTIONAL> sortedRecords;
                using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
                {
                    var query = unitOfWork.MA_PROFILE_FUNCTIONALRepository.GetAll().AsQueryable();
                    Guid guTemp;

                    //Filters
                    if (Guid.TryParse(strfunction, out guTemp)) //Function
                    {
                        query = query.Where(p => p.FUNCTIONAL_ID == Guid.Parse(strfunction));
                    }
                    if (Guid.TryParse(strprofile, out guTemp)) //profile
                    {
                        query = query.Where(p => p.USER_PROFILE_ID == Guid.Parse(strprofile));
                    }

                    //Sorting
                    string[] sortsp = sorting.Split(' ');
                    IQueryable<MA_PROFILE_FUNCTIONAL> orderedRecords = query.OrderBy(sortsp[0], sortsp[1]);
                    sortedRecords = orderedRecords.ToList();
                }

                return sortedRecords.ToList();

            }
            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
Exemple #4
0
 public DA_TRN CancelDeal(SessionInfo sessioninfo, DA_TRN trn)
 {
     LookupBusiness _lookupBusiness = new LookupBusiness();
     using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
     {
         var foundTrn = unitOfWork.DA_TRNRepository.GetById(trn.ID,true);
         if (foundTrn == null)
             throw this.CreateException(new Exception(), "Data not found!");
         else if (!Guid.Equals(foundTrn.LOG.INSERTBYUSERID, sessioninfo.CurrentUserId))
         {
             throw this.CreateException(new Exception(), "You have no right to cancel this transaction");
         }
         else if (!(foundTrn.ENGINE_DATE.Date == sessioninfo.Process.CurrentDate && foundTrn.SOURCE == "INT"))
         {
             throw this.CreateException(new Exception(), "You cannot cancel the past deals");
         }
         else
         {
             //foundTrn.STATUS_ID = new Guid("1ccd7506-b98c-4afa-838e-24378d9b3c2e");
             foundTrn.REMARK = trn.REMARK;
             foundTrn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.CANCELLED.ToString()).ID;
             foundTrn.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId;
             foundTrn.LOG.MODIFYDATE = DateTime.Now;
             trn = foundTrn;
             unitOfWork.Commit();
         }
     }
     return trn;
 }
        public void TraceAuditLoginUser(SessionInfo sessioninfo)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {

                List<DA_LOGIN_AUDIT> foundaudits = unitOfWork.DA_LOGIN_AUDITRepository.GetByUserID(sessioninfo.CurrentUserId);
                if (foundaudits.Count > 0)
                {
                    foreach (DA_LOGIN_AUDIT foundaudit in foundaudits.Where(p => !p.LOGOUT_DATE.HasValue))
                    {
                        foundaudit.LOGOUT_DATE = DateTime.Now;
                        foundaudit.RESULT = String.Format("Logout the system on {0}, because someone use this user to login the system from another machine or computer place.", DateTime.Now.ToString());
                    }
                }
                DA_LOGIN_AUDIT audit = new DA_LOGIN_AUDIT();
                audit.ID = sessioninfo.ID;
                audit.LOG.INSERTBYUSERID = sessioninfo.CurrentUserId;
                audit.LOG.INSERTDATE = DateTime.Now;
                audit.LOGON_DATE = DateTime.Now;
                audit.RESULT = "Logon System";
                audit.TERMINAL = sessioninfo.IPAddress;
                audit.USER_ID = sessioninfo.CurrentUserId;
                unitOfWork.DA_LOGIN_AUDITRepository.Add(audit);
                unitOfWork.Commit();
            }
        }
        public List<MA_LIMIT_PRODUCT> GetLimitProductByFilter(SessionInfo sessioninfo,string strproduct,string strlimit, string sorting)
        {
            try
            {
                IEnumerable<MA_LIMIT_PRODUCT> sortedRecords;
                using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
                {
                    var query = unitOfWork.MA_LIMIT_PRODUCTRepository.GetAll().AsQueryable();
                    Guid guTemp;

                    //Filters
                    if (Guid.TryParse(strproduct, out guTemp)) //Function
                    {
                        query = query.Where(p => p.PRODUCT_ID == Guid.Parse(strproduct));
                    }
                    if (Guid.TryParse(strlimit, out guTemp)) //profile
                    {
                        query = query.Where(p => p.LIMIT_ID == Guid.Parse(strlimit));
                    }

                    //Sorting
                    string[] sortsp = sorting.Split(' ');
                    IQueryable<MA_LIMIT_PRODUCT> orderedRecords = query.OrderBy(sortsp[0], sortsp[1]);
                    sortedRecords = orderedRecords.ToList();
                }
                //Return result to jTable
                return sortedRecords.ToList();

            }
            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
        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 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 MA_USER_PROFILE UpdateUserProfile(SessionInfo sessioninfo, MA_USER_PROFILE userprofile)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_USER_PROFILERepository.GetAll().FirstOrDefault(p => p.LABEL.ToLower().Equals(userprofile.LABEL.ToLower()) && p.ID != userprofile.ID);
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), "Profile is duplicated");

                var founduserprofile = unitOfWork.MA_USER_PROFILERepository.All().FirstOrDefault(p => p.ID == userprofile.ID);
                if (founduserprofile == null)
                    throw this.CreateException(new Exception(), "Data not found!");
                else
                {

                    founduserprofile.ID = userprofile.ID;
                    founduserprofile.LABEL = userprofile.LABEL;
                    founduserprofile.ISACTIVE = userprofile.ISACTIVE;

                    unitOfWork.Commit();

                }
            }

            return userprofile;
        }
        public MA_LIMIT_PRODUCT UpdateLimitProduct(SessionInfo sessioninfo, MA_LIMIT_PRODUCT limitproduct)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_LIMIT_PRODUCTRepository.GetAll().FirstOrDefault(p => p.LIMIT_ID == limitproduct.LIMIT_ID & p.PRODUCT_ID == limitproduct.PRODUCT_ID && p.ID != limitproduct.ID);
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), Messages.DUPLICATE_DATA);

                var foundlimitproduct = unitOfWork.MA_LIMIT_PRODUCTRepository.All().FirstOrDefault(p => p.ID == limitproduct.ID);
                if (foundlimitproduct == null)
                    throw this.CreateException(new Exception(), Messages.DATA_NOT_FOUND);
                else
                {

                    foundlimitproduct.ID = limitproduct.ID;
                    foundlimitproduct.LIMIT_ID = limitproduct.LIMIT_ID;
                    foundlimitproduct.MA_LIMIT = limitproduct.MA_LIMIT;
                    foundlimitproduct.MA_PRODUCT = limitproduct.MA_PRODUCT;
                    foundlimitproduct.PRODUCT_ID = limitproduct.PRODUCT_ID;

                    unitOfWork.Commit();

                }
            }

            return limitproduct;
        }
        public List<MA_USER_PROFILE> GetProfileByFilter(SessionInfo sessioninfo, string name, string sorting)
        {
            try
            {
                //IEnumerable<MA_USER> query;
                IEnumerable<MA_USER_PROFILE> sortedRecords;
                using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
                {
                    var query = unitOfWork.MA_USER_PROFILERepository.GetAll().AsQueryable();

                    //Filters
                    if (!string.IsNullOrEmpty(name))
                    {
                        query = query.Where(p => p.LABEL.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0);
                    }
                    //Sorting
                    string[] sortsp = sorting.Split(' ');
                    IQueryable<MA_USER_PROFILE> orderedRecords = query.OrderBy(sortsp[0], sortsp[1]);
                    sortedRecords = orderedRecords.ToList();
                }
                //Return result to jTable
                return sortedRecords.ToList();

            }
            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
Exemple #12
0
 public DA_LOGIN_AUDIT GetUserLogged(SessionInfo sessioninfo)
 {
     using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
     {
         //return unitOfWork.DA_LOGIN_AUDITRepository.GetBySessionInfo(sessioninfo);
         return unitOfWork.DA_LOGIN_AUDITRepository.GetByID(sessioninfo.ID);
     }
 }
 public List<MA_USER_PROFILE> GetProfileOptions()
 {
     List<MA_USER_PROFILE> profileList;
     using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
     {
         profileList = unitOfWork.MA_USER_PROFILERepository.GetAll();
     }
     return profileList;
 }
Exemple #14
0
 public List<MA_USER> GetAll()
 {
     List<MA_USER> userList;
     using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
     {
         userList = unitOfWork.MA_USERRepository.GetAll().OrderBy(p => p.NAME).ToList();
     }
     return userList;
 }
Exemple #15
0
 public void DeleteUser(SessionInfo sessioninfo, Guid ID)
 {
     using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
     {
         var foundUser = unitOfWork.MA_USERRepository.All().FirstOrDefault(p => p.ID == ID);
         unitOfWork.MA_USERRepository.Delete(foundUser);
         unitOfWork.Commit();
     }
 }
        public void ImportCashflows(SessionInfo sessioninfo, List<DA_TRN_CASHFLOW> cashflows)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                foreach (DA_TRN_CASHFLOW cashflow in cashflows)
                {
                    unitOfWork.DA_TRN_CASHFLOWRepository.Add(cashflow);
                }

                unitOfWork.Commit();
            }
        }
 public void DeleteProfileFunction(SessionInfo sessioninfo, Guid guID)
 {
     using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
     {
         var foundprofilefunction = unitOfWork.MA_PROFILE_FUNCTIONALRepository.All().FirstOrDefault(p => p.ID == guID);
         if (foundprofilefunction == null)
             throw this.CreateException(new Exception(), Messages.DATA_NOT_FOUND);
         else
         {
             unitOfWork.MA_PROFILE_FUNCTIONALRepository.Delete(foundprofilefunction);
             unitOfWork.Commit();
         }
     }
 }
        public MA_PCCF CreatePCCF(SessionInfo sessioninfo, MA_PCCF pccf)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_PCCFRepository.GetAll().FirstOrDefault(p => p.LABEL.ToLower().Equals(pccf.LABEL.ToLower()));
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), Messages.DUPLICATE_DATA);

                unitOfWork.MA_PCCFRepository.Add(pccf);
                unitOfWork.Commit();
            }

            return pccf;
        }
        public MA_FUNCTIONAL CreateFunction(SessionInfo sessioninfo, MA_FUNCTIONAL function)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_FUNCTIONALRepository.GetAll().FirstOrDefault(p => p.USERCODE.ToLower().Equals(function.USERCODE.ToLower()));
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), Messages.DUPLICATE_DATA);

                unitOfWork.MA_FUNCTIONALRepository.Add(function);
                unitOfWork.Commit();
            }

            return function;
        }
Exemple #20
0
 public void TraceAuditLogoutUser(SessionInfo sessioninfo)
 {
     using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
     {
         //DA_LOGIN_AUDIT foundaudit = unitOfWork.DA_LOGIN_AUDITRepository.GetBySessionInfo(sessioninfo);
         DA_LOGIN_AUDIT foundaudit = unitOfWork.DA_LOGIN_AUDITRepository.GetByID(sessioninfo.ID);
         if (foundaudit != null)
         {
             foundaudit.LOGOUT_DATE = DateTime.Now;
             foundaudit.RESULT = String.Format("Logout the system on {0}", DateTime.Now.ToString());
         }
         unitOfWork.Commit();
     }
 }
        public MA_USER_PROFILE CreateUserProfile(SessionInfo sessioninfo, MA_USER_PROFILE userprofile)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_USER_PROFILERepository.GetAll().FirstOrDefault(p => p.LABEL.ToLower().Equals(userprofile.LABEL.ToLower()));
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), "Profile is duplicated");

                unitOfWork.MA_USER_PROFILERepository.Add(userprofile);
                unitOfWork.Commit();
            }

            return userprofile;
        }
        public MA_PROFILE_FUNCTIONAL CreateProfileFunction(SessionInfo sessioninfo, MA_PROFILE_FUNCTIONAL profilefunction)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                if (ValidateProfileFunction(profilefunction))
                {
                    unitOfWork.MA_PROFILE_FUNCTIONALRepository.Add(profilefunction);
                    unitOfWork.Commit();
                }
                else
                    throw this.CreateException(new Exception(), Messages.DUPLICATE_DATA);
            }

            return profilefunction;
        }
        public MA_LIMIT_PRODUCT CreateLimitProduct(SessionInfo sessioninfo, MA_LIMIT_PRODUCT limitproduct)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                if (ValidateProfileFunction(limitproduct))
                {
                    unitOfWork.MA_LIMIT_PRODUCTRepository.Add(limitproduct);
                    unitOfWork.Commit();
                }
                else
                    throw this.CreateException(new Exception(), Messages.DUPLICATE_DATA);
            }

            return limitproduct;
        }
Exemple #24
0
        public MA_USER CreateUser(SessionInfo sessioninfo, MA_USER user)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_USERRepository.GetByUserCode(user.USERCODE);
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), Messages.DUPLICATE_DATA);
                LogBusiness logBusiness = new LogBusiness();
                unitOfWork.DA_LOGGINGRepository.Add(logBusiness.CreateLogging(sessioninfo, user.ID, LogEvent.USER_AUDIT.ToString(), LookupFactorTables.MA_USER, "User", new { }));
                unitOfWork.MA_USERRepository.Add(user);
                unitOfWork.Commit();
            }

            return user;
        }
        public void UpdateDealReconcile(SessionInfo sessioninfo, List<DealTranModel> trns)
        {
            DealBusiness _dealBusiness = new DealBusiness();
            LoggingHelper.Debug("Begin UpdateDealReconcile....");
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                foreach (DealTranModel tran in trns)
                {
                    switch (tran.UpdateStates)
                    {
                        case UpdateStates.Adding:
                            unitOfWork.DA_TRNRepository.Add(tran.Transaction);
                            LoggingHelper.Debug(String.Format("Insert DA_TRN {0} [{1}] is completed", tran.Transaction.INT_DEAL_NO, tran.Transaction.ID.ToString()));
                            break;
                        case  UpdateStates.Editing:
                            var update = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == tran.Transaction.ID);
                            if (update == null)
                                throw this.CreateException(new Exception(), "Data not found!");
                            else
                            {
                                update.EXT_DEAL_NO = tran.Transaction.EXT_DEAL_NO;
                                update.EXT_PORTFOLIO = tran.Transaction.EXT_PORTFOLIO;
                                update.MATURITY_DATE = tran.Transaction.MATURITY_DATE;
                                update.STATUS_ID = tran.Transaction.STATUS_ID;
                                update.LOG.MODIFYBYUSERID = tran.Transaction.LOG.MODIFYBYUSERID;
                                update.LOG.MODIFYDATE = tran.Transaction.LOG.MODIFYDATE;
                                update.INSERT_BY_EXT = tran.Transaction.INSERT_BY_EXT;

                            }
                            LoggingHelper.Debug(String.Format("Update DA_TRN {0} [{1}] is completed", update.INT_DEAL_NO, update.ID.ToString()));
                            break;
                        case UpdateStates.Deleting:
                            var delete = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == tran.Transaction.ID);
                            if (delete == null)
                                throw this.CreateException(new Exception(), "Data not found!");
                            else
                                unitOfWork.DA_TRNRepository.Delete(delete);

                            LoggingHelper.Debug(String.Format("Delete DA_TRN {0} [{1}] is completed", delete.INT_DEAL_NO, delete.ID.ToString()));
                            break;
                    }
                }

                unitOfWork.Commit();

                LoggingHelper.Debug("Commit UpdateDealReconcile....");
            }
        }
        public List<MA_FUNCTIONAL> GetFunctionByFilter(SessionInfo sessioninfo, string name, string sorting)
        {
            try
            {
                //IEnumerable<MA_USER> query;
                IEnumerable<MA_FUNCTIONAL> sortedRecords;
                using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
                {
                    var query = unitOfWork.MA_FUNCTIONALRepository.GetAll().AsQueryable();

                    //Filters
                    if (!string.IsNullOrEmpty(name))
                    {
                        query = query.Where(p => p.USERCODE.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0);
                    }
                    //IQueryable<MA_FUNCTIONAL> orderedRecords = null;
                    ////Sorting
                    //if (string.IsNullOrEmpty(sorting) || sorting.Equals("LABEL ASC"))
                    //{
                    //    orderedRecords = query.OrderBy(p => p.LABEL).AsQueryable();
                    //}
                    //else if (sorting.Equals("LABEL DESC"))
                    //{
                    //    orderedRecords = query.OrderByDescending(p => p.LABEL).AsQueryable();
                    //}
                    //else
                    //{
                    //    orderedRecords = query.OrderBy(p => p.LABEL).AsQueryable(); //Default!
                    //}
                    //sortedRecords = orderedRecords.ToList();

                    //Sorting
                    string[] sortsp = sorting.Split(' ');
                    IQueryable<MA_FUNCTIONAL> orderedRecords = query.OrderBy(sortsp[0], sortsp[1]);
                    sortedRecords = orderedRecords.ToList();
                    //if (sortsp[1].ToLower() == "desc") sortedRecords = sortedRecords.Reverse();
                }
                //Return result to jTable
                return sortedRecords.ToList();

            }
            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
        public MA_PROCESS_DATE Get()
        {
            try
            {
                MA_PROCESS_DATE prcDate = null;

                using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
                {
                    prcDate = unitOfWork.MA_PROCESS_DATERepository.All().First();
                }

                return prcDate;
            }
            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
 public List<PermisionModel> GetPermissionByProfileID(Guid guProfileID)
 {
     List<PermisionModel> permissions = null;
     using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
     {
         var query = unitOfWork.MA_PROFILE_FUNCTIONALRepository.GetByUserProfileId(guProfileID)
                             .Select(p => new PermisionModel
                             {
                                 FunctionalCode = p.MA_FUNCTIONAL.USERCODE,
                                 FunctionalLabel = p.MA_FUNCTIONAL.LABEL,
                                 IsReadable = p.ISREADABLE,
                                 IsWritable = p.ISWRITABLE,
                                 IsApprovable = p.ISAPPROVABLE
                             });
         permissions = query.ToList();
     }
     return permissions;
 }
        public MA_INSTRUMENT Create(SessionInfo sessioninfo, MA_INSTRUMENT instrument, ProductCode product)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_INSTRUMENTRepository.GetAllByProductCode(product.ToString()).FirstOrDefault(p => p.LABEL == instrument.LABEL);
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), "Label is duplicated");
                if (product == ProductCode.BOND)
                {
                    LogBusiness logBusiness = new LogBusiness();
                    unitOfWork.DA_LOGGINGRepository.Add(logBusiness.CreateLogging(sessioninfo, instrument.ID, LogEvent.INSTRUMENT_AUDIT.ToString(), LookupFactorTables.MA_INSTRUMENT, "BOND", new { }));
                }
                unitOfWork.MA_INSTRUMENTRepository.Add(instrument);
                unitOfWork.Commit();
            }

            return instrument;
        }
        public MA_PROCESS_DATE Update(SessionInfo sessioninfo, MA_PROCESS_DATE processdate)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var found = unitOfWork.MA_PROCESS_DATERepository.All().First();
                if (found == null)
                    throw this.CreateException(new Exception(), "Data not found!");
                else
                {

                    found.NEXT_PROC_DATE = processdate.NEXT_PROC_DATE;
                    found.PREV_PROC_DATE = processdate.PREV_PROC_DATE;
                    found.PROC_DATE = processdate.PROC_DATE;
                    found.FLAG_RECONCILE = processdate.FLAG_RECONCILE;
                    found.LOG.MODIFYBYUSERID = processdate.LOG.MODIFYBYUSERID;
                    found.LOG.MODIFYDATE = processdate.LOG.MODIFYDATE;
                    found.FLAG_RECONCILE = processdate.FLAG_RECONCILE;
                    unitOfWork.Commit();

                }
            }

            return processdate;
        }