private bool CheckForUnapprovedEntries(DBDocument allocationEntry) { logger.LogTrace("Checking whether allocation has unapproved entries"); bool hasUnapprovedEntries = false; var query = new DBQuery("homescreenprojects", "unapprovedentriesforproject"); query.AddParameter("project", allocationEntry["project"]); query.AddParameter("user", allocationEntry["user"]); DBResponse response = query.Find(); if (response["timesheetentry"].Count > 0) { hasUnapprovedEntries = true; } else if (response["absenceentry"].Count > 0) { hasUnapprovedEntries = true; } else if (response["dayentry"].Count > 0) { hasUnapprovedEntries = true; } else if (response["articleentry"].Count > 0) { hasUnapprovedEntries = true; } return(hasUnapprovedEntries); }
public ActionResult approveday(string selectedday) { DateTime day = DateTime.ParseExact(selectedday, "yyyyMMdd", CultureInfo.InvariantCulture); day = new DateTime(day.Year, day.Month, day.Day, day.Hour, day.Minute, day.Second, DateTimeKind.Utc); var query = new DBQuery("workentries", "unacceptedentrydata"); query.AddParameter("start", day); query.AddParameter("end", day); query.AddParameter("user", new ObjectId(Runtime.SessionManager.CurrentUser[DBQuery.Id])); DBResponse response = query.Find(); DBCollection timesheetEntries = response["timesheetentry"]; DBCollection abseneceEntries = response["absenceentry"]; DBCollection dayEntries = response["dayentry"]; DBCollection articleEntries = response["articleentry"]; DBCollection assetEntries = response["assetentry"]; var tasks = new List <Task <DBUpdateResponse> >(); tasks.Add(ApproveEntriesInCollection(timesheetEntries)); tasks.Add(ApproveEntriesInCollection(abseneceEntries)); tasks.Add(ApproveEntriesInCollection(dayEntries)); tasks.Add(ApproveEntriesInCollection(articleEntries)); tasks.Add(ApproveEntriesInCollection(assetEntries)); Task.WaitAll(tasks.ToArray()); return(new AjaxResult("success")); }
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.")); } }
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)); }
public ActionResult projectallocations(string projectid, string selectedday, string projectname) { DateTime day = DateTime.ParseExact(selectedday, "yyyyMMdd", CultureInfo.InvariantCulture); day = new DateTime(day.Year, day.Month, day.Day, day.Hour, day.Minute, day.Second, DateTimeKind.Utc); var query = new DBQuery("homescreenprojects", "allocationsforproject"); query.AddParameter("project", new ObjectId(projectid)); query.AddParameter("start", day); query.AddParameter("end", day); return(View((DataTree)query.Find().FirstCollection, projectname)); }
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)); }
public ActionResult gateurllogin(DataTree formParameters) { logger.LogInfo("Gate url login called."); string redirectUrl = string.Empty; try { DataTree common = LegacyRegister.ContentDataToDataTree((string)formParameters["yleiset_contentdata"]); DataTree menu = LegacyRegister.ContentDataToDataTree((string)formParameters["menureg_contentdata"]); DataTree silmu2 = LegacyRegister.ContentDataToDataTree((string)formParameters["silmu2_contentdata"]); string loginGuid = (string)formParameters["sov_varmistus_guid"]; if (string.IsNullOrEmpty(loginGuid) || loginGuid != (string)Runtime.Config["security"]["loginguid"]) { logger.LogWarning("Login attempt with invalid login GUID"); throw new AccessDeniedException(); } string userEmail = (string)silmu2["account"]["email"].GetValueOrDefault(string.Empty); var userQuery = new DBQuery("core", "userbyemail"); userQuery.AddParameter("email", userEmail); // User must be found when redirecting to addresses DataTree user = userQuery.FindOneAsync().Result; if (user == null) { return(new AjaxResult(SilmuErrorHeader + "User was not found in database.")); } string target = (string)silmu2["app"]["parameters"]["target"].GetValueOrDefault(String.Empty); string url = (string)silmu2["app"]["parameters"]["url"].GetValueOrDefault(String.Empty); if (!string.IsNullOrEmpty(target)) { redirectUrl = Runtime.Config["gateurls"][target]; } else { redirectUrl = url; } if (string.IsNullOrEmpty(redirectUrl)) { return(new AjaxResult(SilmuErrorHeader + "Redirect url was not found.")); } Interlocked.Increment(ref gateUserRedirects); } catch (Exception ex) { return(new AjaxResult(SilmuErrorHeader + ex.ToString())); } return(new AjaxResult("<url>" + redirectUrl + "</url>")); }
/// <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); }
public ActionResult getEntryData(DateTime start, DateTime end) { var entriesQuery = new DBQuery("workdatawidget", "entrydata"); entriesQuery.AddParameter("user", Runtime.SessionManager.CurrentUser[DBQuery.Id]); entriesQuery.AddParameter("start", start); entriesQuery.AddParameter("end", end); DBResponse response = entriesQuery.Find(); var allocations = response["allocationentry"]; foreach (DBDocument allocation in allocations) { allocation["project"] = DBDocument.FindOne("project", allocation["project"][DBDocument.Id]); } return(new AjaxResult((DataTree)response)); }
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; } } }
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); }
public ActionResult pasteday(string sourceday, string targetday) { if ((bool)Runtime.Features["timetracking"]) { return(new AjaxResult("Copying not supported for timetracking.")); } logger.LogInfo("copying entries from one date to another", sourceday, targetday); DateTime sourceDay = DateTime.ParseExact(sourceday, "yyyyMMdd", CultureInfo.InvariantCulture); sourceDay = new DateTime(sourceDay.Year, sourceDay.Month, sourceDay.Day, sourceDay.Hour, sourceDay.Minute, sourceDay.Second, DateTimeKind.Utc); DateTime targetDay = DateTime.ParseExact(targetday, "yyyyMMdd", CultureInfo.InvariantCulture); targetDay = new DateTime(targetDay.Year, targetDay.Month, targetDay.Day, targetDay.Hour, targetDay.Minute, targetDay.Second, DateTimeKind.Utc); var query = new DBQuery("workentries", "workforday"); query.AddParameter("start", sourceDay); query.AddParameter("end", sourceDay); query.AddParameter("user", new ObjectId(Runtime.SessionManager.CurrentUser[DBQuery.Id])); DBResponse response = query.Find(); DBCollection timesheetEntries = response["timesheetentry"]; DBCollection abseneceEntries = response["absenceentry"]; DBCollection dayEntries = response["dayentry"]; var tasks = new List <Task <bool> >(); bool isTargetInThePast = (DateTime.Compare(DateTime.UtcNow, targetDay) > 0); // Only ever copy absences for future if (isTargetInThePast) { tasks.Add(CopyEntriesToDay(timesheetEntries, targetDay)); tasks.Add(CopyEntriesToDay(dayEntries, targetDay)); tasks.Add(CopyEntriesToDay(abseneceEntries, targetDay)); } else { logger.LogDebug("Copy target date is in the future"); if ((bool)Runtime.Features["allowfutureabsences"]) { tasks.Add(CopyEntriesToDay(abseneceEntries, targetDay)); } } Task.WaitAll(tasks.ToArray()); bool somethingFiltered = false; foreach (var task in tasks) { if (task.Result) { somethingFiltered = true; } } return(new AjaxResult(somethingFiltered ? "filtered" : "success")); }
private void AddParameterToQuery(string name, string parameter, DBQuery query) { const string ParameterTypeString = "string"; const string ParameterTypeNumber = "number"; const string ParameterTypeDateTime = "date"; const string ParameterTypeObjectId = "objectid"; const string ParameterTypeNull = "null"; const string ParameterTypeBool = "bool"; int split = parameter.IndexOf(":"); if (split == -1) { return; } string type = parameter.Substring(0, split); string value = parameter.Substring(split + 1); if (type == ParameterTypeString) { query.AddParameter(name, value); } else if (type == ParameterTypeNumber) { double number = 0; try { number = Convert.ToDouble(value, CultureInfo.InvariantCulture); } catch (Exception) { throw new RuntimeException("Invalid number value", new string[] { parameter }); } query.AddParameter(name, number); } else if (type == ParameterTypeDateTime) { MC2DateTimeValue dateTime = null; try { dateTime = (MC2DateTimeValue)MC2DateTimeValue.TryConvertValueFromString(value); } catch (Exception) { throw new RuntimeException("Invalid date time value", new string[] { parameter }); } query.AddParameter(name, dateTime); } else if (type == ParameterTypeObjectId) { if (string.IsNullOrEmpty(value)) { // Add empty object id if value is empty query.AddParameter(name, new ObjectId()); } else { ObjectId objectId = new ObjectId(); try { objectId = new ObjectId(value); } catch (Exception) { throw new RuntimeException("Invalid object id value", new string[] { parameter }); } query.AddParameter(name, objectId); } } else if (type == ParameterTypeNull) { query.AddNullParameter(name); } else if (type == ParameterTypeBool) { if (value == "true") { query.AddParameter(name, true); } else if (value == "false") { query.AddParameter(name, false); } else { throw new RuntimeException("Invalid value for boolean parameter", new string[] { name, value }); } } }