public IList GetWorkingTimeRecordingsByEmployeeIds(long[] employeeIDs, DateTime beginDate, DateTime endDate)
        {
            if ((employeeIDs == null) || (employeeIDs.Length == 0))
            {
                return(null);
            }

            /*IList result = Session.CreateCriteria(typeof(WorkingTimeRecording))
             *  .Add(Expression.Ge("Date", beginDate))
             *  .Add(Expression.Le("Date", endDate))
             *  .Add(Expression.In("EmployeeID", employeeIDs))
             *  .//List();*/

            List <string> pNames  = new List <string>();
            List <object> pValues = new List <object>();
            StringBuilder hql     = new StringBuilder(" entity.Date >= :begin_date AND entity.Date <= :end_date ");

            pNames.Add("begin_date");
            pValues.Add(beginDate);
            pNames.Add("end_date");
            pValues.Add(endDate);
            string ids = QueryUtils.GenIDList(employeeIDs, pNames, pValues);

            if ((ids != null) && (ids.Length > 0))
            {
                hql.AppendFormat(" AND entity.EmployeeID IN ({0}) ", ids);
            }
            IList result = FindByNamedParam(hql.ToString(), pNames.ToArray(), pValues.ToArray());

            if ((result == null) || (result.Count == 0))
            {
                return(null);
            }
            return(result);
        }
Esempio n. 2
0
        public Dictionary <long, World> GetDictionaryByStoreToWorldIDList(IEnumerable <long> idList)
        {
            List <string> pNames  = new List <string>();
            List <object> pValues = new List <object>();

            StringBuilder sb = new StringBuilder(50);

            sb.Append("entity.ID=sw.WorldID AND sw.ID IN (");
            sb.Append(QueryUtils.GenIDList(idList, pNames, pValues));
            sb.Append(")");

            IList list =
                FindByNamedParam(new string[] { "sw.ID", "entity" }, "StoreToWorld sw", sb.ToString(), "",
                                 pNames.ToArray(), pValues.ToArray(), true);

            if ((list == null) || (list.Count == 0))
            {
                return(null);
            }

            Dictionary <long, World> result = new Dictionary <long, World>(list.Count);

            foreach (object[] array in list)
            {
                result.Add((long)array[0], (World)array[1]);
            }
            return(result);
        }
Esempio n. 3
0
        private void MergeResourceListWithSavedResources(ICollection <UIResource> list)
        {
            if ((list == null) || (list.Count == 0))
            {
                return;
            }

            // prepare dictionary for selecting from DB
            Dictionary <long, List <int> > curResDictionary = new Dictionary <long, List <int> >(2);

            foreach (UIResource entity in list)
            {
                if (curResDictionary.ContainsKey(entity.LanguageID))
                {
                    long langId = entity.LanguageID;
                    if (curResDictionary[langId] == null)
                    {
                        curResDictionary[langId] = new List <int>();
                    }
                    curResDictionary[langId].Add(entity.ResourceID);
                }
                else
                {
                    curResDictionary.Add(entity.LanguageID, new List <int>(new int[] { entity.ResourceID }));
                }
            }

            // select current resources for merge
            // 2think: should we implement reading in the one "SELECT" with big condition string and many parameters?
            StringBuilder     condition      = new StringBuilder();
            List <string>     pNames         = new List <string>();
            List <object>     pValues        = new List <object>();
            List <UIResource> savedResources = new List <UIResource>();

            foreach (long langId in curResDictionary.Keys)
            {
                condition.Length = 0;
                pNames.Clear();
                pValues.Clear();
                pNames.Add("langid");
                pValues.Add(langId);
                condition.AppendFormat("entity.LanguageID = :langid AND entity.ResourceID IN ({0})",
                                       QueryUtils.GenIDList(
                                           curResDictionary[langId].ConvertAll <long>(
                                               delegate(int value) { return(value); }), pNames, pValues));
                List <UIResource> curLanguageResources =
                    TypedListConverter <UIResource> .ToTypedList(
                        _resDao.FindByNamedParam(condition.ToString(), pNames.ToArray(), pValues.ToArray()));

                if ((curLanguageResources != null) && (curLanguageResources.Count > 0))
                {
                    savedResources.AddRange(curLanguageResources);
                }
            }

            // merge IDs
            if (savedResources.Count > 0)
            {
                foreach (UIResource entity in list)
                {
                    if (entity.ID <= 0)
                    {
                        if (curResDictionary.ContainsKey(entity.LanguageID))
                        {
                            long       langId        = entity.LanguageID;
                            UIResource savedResource =
                                savedResources.Find(
                                    delegate(UIResource res)
                            {
                                return((res.LanguageID == langId) &&
                                       (res.ResourceID == entity.ResourceID));
                            });
                            if (savedResource != null)
                            {
                                entity.ID = savedResource.ID;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
    /// <summary>
    /// Returns receivers that should be called.
    /// </summary>
    /// <param name="cachedReceiverList">All registered receivers (read-only cached array).</param>
    /// <param name="iMessage">The call.</param>
    /// <returns>Receivers that will be called.</returns>
    public object[] GetReceivers(object[] cachedReceiverList,
                                 IMessage iMessage)
    {
        // get string immediately from the call
        IMethodCallMessage iMethodCallMessage =
            (IMethodCallMessage)iMessage;
        IEnumerable <long> ids = iMethodCallMessage.Args[0] as IEnumerable <long>;

        if (ids == null)
        {
            return((new List <object>(cachedReceiverList)).ToArray());
        }

        // construct result list that will contain filtered receivers
        object[] resultList         = new object[cachedReceiverList.Length];
        int      resultListPosition = 0;

        AuthorizationService authSvc = (AuthorizationService)ServerEnvironment.AuthorizationService;

        // go though all the receivers
        for (int i = 0; i < cachedReceiverList.Length; i++)
        {
            // get the next receiver
            ReceiverInfo receiverInfo = cachedReceiverList[i] as ReceiverInfo;
            if (receiverInfo == null)
            {
                continue;
            }

            // obtain its session
            ISessionSupport session = (ISessionSupport)receiverInfo.Tag;
            User            u       = authSvc.GetUser(session["id"] as SessionId);
            if ((u == null) || (!u.UserRoleID.HasValue))
            {
                continue;
            }

            if (!((UserRoleId)(u.UserRoleID.Value) == UserRoleId.GlobalAdmin) && !_svc.Dao.IsPermittedAll(u, true))
            {
                List <string> pNames  = new List <string>();
                List <object> pValues = new List <object>();
                string        idList  = QueryUtils.GenIDList(ids, pNames, pValues);
                int           idCount = pValues.Count;
                IList         list    =
                    _svc.Dao.FindByNamedParam(new string[] { "entity.ID" }, null, string.Format("entity.ID IN ({0})", idList),
                                              null, pNames.ToArray(), pValues.ToArray(), true, u);
                if ((list == null) || (list.Count == 0))
                {
                    continue;
                }

                if (idCount != list.Count)
                {
                    List <long> newIds = new List <long>(list.Count);
                    foreach (long id in list)
                    {
                        newIds.Add(id);
                    }
                    iMethodCallMessage.Args[0] = newIds;
                }
            }

            resultList[resultListPosition++] = receiverInfo;
        }

        return(resultList);
    }