Ejemplo n.º 1
0
        public ActionResult getstatus()
        {
            var monitorQuery = new DBQuery();

            monitorQuery["monitorinfo"][DBQuery.Condition] = DBQuery.All;

            string result = "";

            try
            {
                DBDocument resultDoc = monitorQuery.FindOne(new DBCallProperties()
                {
                    RunWithPrivileges = 5
                });

                if (resultDoc == null)
                {
                    return(new AjaxResult("ERROR. No result document found. To configure monitoring add monitorinfo collection to schema and insert one document with the desired response."));
                }

                result = resultDoc["info"];
            }
            catch (Exception ex)
            {
                result = "error: " + ex;
            }

            return(new AjaxResult(result));
        }
Ejemplo n.º 2
0
        public ActionResult impersonate(DataTree formData)
        {
            // Handle impersonation
            string userId = formData["user"];

            bool success = true;

            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    success = false;
                }

                if (success)
                {
                    DBQuery userQuery = new DBQuery();

                    userQuery["user"][DBQuery.Condition] = Query.EQ("_id", new ObjectId(userId))
                                                           .ToString();

                    DataTree user = userQuery.FindOne();
                    Runtime.SessionManager.UnauthenticatedLogin(user["email"]);

                    return(Redirect(Runtime.HistoryManager.GetPreviousAddress()));
                }
            }
            catch (Exception)
            {
                success = false;
                logger.LogError("Failed to impersonate", userId);
            }

            return(View(success));
        }
Ejemplo n.º 3
0
        public ActionResult startworkonproject(string projectid)
        {
            if (!string.IsNullOrEmpty(projectid))
            {
                // When starting work first look for existing allocation without date. If we have one we should
                // start that allocation instead of generating a new one.
                var existingAllocationQuery = new DBQuery("startproject", "unscheduledallocation");
                existingAllocationQuery.AddParameter("user", new ObjectId(Runtime.SessionManager.CurrentUser["_id"]));
                existingAllocationQuery.AddParameter("project", new ObjectId(projectid));

                DBDocument allocationEntry = existingAllocationQuery.FindOne();

                if (allocationEntry == null)
                {
                    allocationEntry = new DBDocument("allocationentry");
                }

                allocationEntry.AddRelation("project", projectid);
                allocationEntry.AddRelation("user", Runtime.SessionManager.CurrentUser["_id"]);
                allocationEntry["status"] = "In progress";

                allocationEntry.UpdateDatabaseAsync();

                return(new AjaxResult("success"));
            }
            else
            {
                return(new AjaxResult("No identifier provided. Cannot start work."));
            }
        }
Ejemplo n.º 4
0
        public static bool AddPayrollFilter(
            string collection,
            string payrollperiodfilter,
            List <IMongoQuery> timesheetEntryAndQueries,
            bool hasFilters = false)
        {
            DataTree payrollPeriod = null;

            if (!string.IsNullOrEmpty(payrollperiodfilter))
            {
                DBQuery payrollPeriodQuery = new DBQuery();
                payrollPeriodQuery["payrollperiod"][DBQuery.Condition] = Query.EQ(DBQuery.Id, new ObjectId(payrollperiodfilter)).ToString();

                payrollPeriod = payrollPeriodQuery.FindOne();

                if (payrollPeriod != null)
                {
                    if (collection == "dayentry")
                    {
                        // Nasty time hack to temporarily fix the issue of date picker not returning utc 00:00 based dates but rather including the time zone.
                        timesheetEntryAndQueries.Add(Query.GT("date", ((DateTime)payrollPeriod["startdate"]).AddHours(-12)));
                        timesheetEntryAndQueries.Add(Query.LTE("date", ((DateTime)payrollPeriod["enddate"]).AddHours(-12)));
                    }
                    else
                    {
                        DateTime startDate = (DateTime)payrollPeriod["startdate"];
                        DateTime endDate   = (DateTime)payrollPeriod["enddate"];

                        // Convert dates to what would be the date's timestamp in local timezone. This is to take in to account the fact
                        // that dates are not timestamps and to compare between date and a datetime we must assign a timezone to the date.
                        startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0, DateTimeKind.Local);
                        endDate   = new DateTime(endDate.Year, endDate.Month, endDate.Day, 0, 0, 0, DateTimeKind.Local);

                        // Return time as UTC. The end result is to shift the Date's corresponding timestamp to whatever UTC
                        // time would be at the local timezone.
                        timesheetEntryAndQueries.Add(Query.GT("starttimestamp", startDate.ToUniversalTime()));
                        timesheetEntryAndQueries.Add(Query.LTE("starttimestamp", endDate.ToUniversalTime()));
                    }

                    timesheetEntryAndQueries.Add(Query.EQ("clacontract", new ObjectId(payrollPeriod["clacontract"])));
                    hasFilters = true;
                }
            }

            return(hasFilters);
        }
Ejemplo n.º 5
0
        public MC2Value trocurrentproject(DataTree itemSchema)
        {
            MC2Value value = null;

            if ((bool)Runtime.CurrentActionCall.Parameters["socialproject"] == true && (bool)Runtime.Config["application"]["features"]["enablesocialproject"])
            {
                // Todo: cache value?
                if (socialProject == null)
                {
                    socialProject = new DBQuery("tro", "getsocialproject").FindOneAsync().Result;
                }

                value = socialProject;
            }
            else if ((bool)Runtime.CurrentActionCall.Parameters["fromhomescreen"] == true)
            {
                // Use either provided project from url or user's project
                if (Runtime.CurrentActionCall.Parameters["workscheduleprojectid"].Exists)
                {
                    value = DBDocument.FindOne("project", Runtime.CurrentActionCall.Parameters["workscheduleprojectid"]);
                }
                else
                {
                    var userQuery = new DBQuery();

                    userQuery["user"][DBQuery.Condition] = Query.EQ(DBQuery.Id, new ObjectId(Runtime.SessionManager.CurrentUser["_id"]))
                                                           .ToString();

                    DataTree currentUser = userQuery.FindOne();

                    value = currentUser["currentproject"];
                }
            }
            else
            {
                value = MC2EmptyValue.EmptyValue;
            }

            return(value);
        }