Ejemplo n.º 1
0
        /// <summary>
        /// Retrun pay types that cout towards hour totals. Usually these include normal working hours,
        /// overtime etc. but not any extra compensations logged for these same hours.
        /// </summary>
        /// <returns></returns>
        public async Task <HashSet <string> > GetPayTypesThatCountAsRegularHours()
        {
            lock (payTypesThatCountAsRegulsrHoursLock)
            {
                if (payTypesThatCountAsRegulsrHours != null)
                {
                    return(payTypesThatCountAsRegulsrHours);
                }
            }

            var        query  = new DBQuery("tro", "logic_paytypesthatcountasregularhours");
            DBResponse result = await query.FindAsync().ConfigureAwait(false);

            lock (payTypesThatCountAsRegulsrHoursLock)
            {
                payTypesThatCountAsRegulsrHours = new HashSet <string>();

                foreach (DBDocument payType in result.FirstCollection)
                {
                    payTypesThatCountAsRegulsrHours.Add(payType[DBQuery.Id]);
                }
            }

            return(payTypesThatCountAsRegulsrHours);
        }
Ejemplo n.º 2
0
        public ActionResult getuserdata(string key)
        {
            var query = new DBQuery("core", "userdata");

            query.AddParameter("user", Runtime.SessionManager.CurrentUser["_id"]);
            query.AddParameter("key", key);

            DBResponse result = query.FindAsync().Result;

            return(new AjaxResult((DataTree)result.FirstCollection));
        }
Ejemplo n.º 3
0
        public AjaxResult allocateasset(
            string asset,
            string project,
            DateTime start,
            DateTime end,
            string status,
            bool ignoreconflicts = false)
        {
            // Get allocations for given date
            string resultValue = "success";

            bool confilictingAllocationFound = false;

            if (!ignoreconflicts)
            {
                DBQuery query = new DBQuery("dailyresourcingwidget", "getassetallocation");
                query.AddParameter("asset", new ObjectId(asset));
                query.AddParameter("start", start);
                query.AddParameter("end", end);

                DBResponse result = query.FindAsync(new DBCallProperties()
                {
                    RunWithPrivileges = 5
                }).Result;

                if (result["allocationentry"].Count > 0)
                {
                    confilictingAllocationFound = true;
                }
            }

            if (confilictingAllocationFound)
            {
                resultValue = "conflict";
            }
            else
            {
                var newAllocation = new DBDocument("allocationentry");
                newAllocation.AddRelation("asset", asset);
                newAllocation.AddRelation("project", project);

                newAllocation["starttimestamp"] = start;
                newAllocation["endtimestamp"]   = end;

                newAllocation.UpdateDatabase();
            }

            return(new AjaxResult(resultValue));
        }
Ejemplo n.º 4
0
        public MC2Value defaultassets(
            string collection,
            string valuename,
            string relationtarget,
            string itemid,
            string filtercontroller,
            string filterblock)
        {
            string projectId = Runtime.HistoryManager.GetCurrentHistoryEntryState()["__form_project"]["formvalue"];

            if (string.IsNullOrEmpty(projectId))
            {
                // Use default project if nothing else is provided
                projectId = ((DataTree)this.trocurrentproject(null))[DBQuery.Id];
            }

            if (string.IsNullOrEmpty(projectId))
            {
                logger.LogDebug("No project when looking for default assets.");
                return(null);
            }

            var query = new DBQuery("tro", "assetentry_defaultassets");

            query.AddParameter("projectid", new ObjectId(projectId));

            var task = query.FindAsync();

            DBCollection projects = task.Result["project"];

            DataTree root   = new DataTree();
            DataTree assets = root["asset"];

            foreach (DataTree project in projects)
            {
                foreach (DataTree allocationEntry in project["allocationentry"])
                {
                    if (allocationEntry["asset"].Count > 0 && !assets.Contains(allocationEntry["asset"][DBQuery.Id]))
                    {
                        assets[allocationEntry["asset"][DBQuery.Id]] = allocationEntry["asset"];
                    }
                }
            }

            return(assets);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get data for single user for single day, cache and return it.
        /// </summary>
        /// <param name="date"></param>
        /// <param name="dateKey"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        private async Task <DataTree> RefreshUserDataForDayAsync(DataTree userTree, DateTime date, string dateKey)
        {
            DateTime dayStart = date;

            var query = new DBQuery("horizontalworkview", "dailyentriesforcache");

            query.AddParameter("date", date);
            query.AddParameter("user", new ObjectId(userTree.Name));

            DBResponse cacheQueryResults = await query.FindAsync();

            DBCollection dayEntries = cacheQueryResults.FirstCollection;

            //CacheSingleDayForUser(userTree, dateKey, dayEntries);

            return((DataTree)dayEntries);
        }
Ejemplo n.º 6
0
        private AjaxResult Find(string controller, string query)
        {
            if (string.IsNullOrEmpty(query))
            {
                throw new RuntimeException("Query missing from find request.");
            }

            if (string.IsNullOrEmpty(controller))
            {
                throw new RuntimeException("Controller missing from find request.");
            }

            DBQuery dbQuery = GetQuery(controller, query);

            ApplyQueryParameters(dbQuery);

            DataTree result = (DataTree)dbQuery.FindAsync().Result;

            return(new AjaxResult(result));
        }
Ejemplo n.º 7
0
        private async Task CacheAllDaysInRangeForUserAsync(DataTree userTree, DateTime start, DateTime end)
        {
            logger.LogTrace("Caching days for user in a single query", userTree.Name, start, end);

            var query = new DBQuery("horizontalworkview", "dailyentriesforcache_range");

            query.AddParameter("start", start);
            query.AddParameter("end", end);
            query.AddParameter("user", new ObjectId(userTree.Name));

            DBResponse queryResult = await query.FindAsync();

            InvalidateDayRange(userTree, start, end);

            // Cache each entry
            foreach (DataTree entryType in queryResult.FirstCollection)
            {
                foreach (DataTree entry in entryType)
                {
                    documents[entry["_id"]] = entry;
                }
            }
        }