public Time(DateTime time) { this.m_absoluteTime = DateTime.MinValue; this.m_baseTime = RelativeTime.Now; this.m_offsets = new TimeOffsetCollection(); this.AbsoluteTime = time; }
// Token: 0x06000726 RID: 1830 RVA: 0x00011CE8 File Offset: 0x00010CE8 private static string BaseTypeToString(RelativeTime baseTime) { switch (baseTime) { case RelativeTime.Now: return("NOW"); case RelativeTime.Second: return("SECOND"); case RelativeTime.Minute: return("MINUTE"); case RelativeTime.Hour: return("HOUR"); case RelativeTime.Day: return("DAY"); case RelativeTime.Week: return("WEEK"); case RelativeTime.Month: return("MONTH"); case RelativeTime.Year: return("YEAR"); default: throw new ArgumentOutOfRangeException("baseTime", baseTime.ToString(), "Invalid value for relative base time."); } }
public string GetEventValue(string Name) { if (EventValues.ContainsKey(Name)) { return(EventValues[Name]); } else if (Name.ToLower() == "eventname") { return(EventName); } else if (Name.ToLower() == "element") { return(Element); } else if (Name.ToLower() == "timestamp") { return(TimeStamp.ToString()); // TODO: Define format } else if (Name.ToLower() == "relativetime") { return(RelativeTime.ToString()); } ; // TODO: Define format return(""); }
// Token: 0x06000725 RID: 1829 RVA: 0x00011C18 File Offset: 0x00010C18 public static Time Parse(string buffer) { buffer = buffer.Trim(); Time time = new Time(); bool flag = false; foreach (object obj in Enum.GetValues(typeof(RelativeTime))) { RelativeTime baseTime = (RelativeTime)obj; string text = Time.BaseTypeToString(baseTime); if (buffer.StartsWith(text)) { buffer = buffer.Substring(text.Length).Trim(); time.BaseTime = baseTime; flag = true; break; } } if (!flag) { time.AbsoluteTime = System.Convert.ToDateTime(buffer).ToUniversalTime(); return(time); } if (buffer.Length > 0) { time.Offsets.Parse(buffer); } return(time); }
// Token: 0x0600072B RID: 1835 RVA: 0x00011D8C File Offset: 0x00010D8C internal static string OffsetTypeToString(RelativeTime offsetType) { switch (offsetType) { case RelativeTime.Second: return("S"); case RelativeTime.Minute: return("M"); case RelativeTime.Hour: return("H"); case RelativeTime.Day: return("D"); case RelativeTime.Week: return("W"); case RelativeTime.Month: return("MO"); case RelativeTime.Year: return("Y"); default: throw new ArgumentOutOfRangeException("offsetType", offsetType.ToString(), "Invalid value for relative time offset type."); } }
private async void LoadHistoryItems() { TextWidget loadingText = new TextWidget("Retrieving History from Web..."); loadingText.TextColor = ActiveTheme.Instance.PrimaryTextColor; scrollWindow.AddChild(loadingText); var results = await ApplicationController.GetProfileHistory?.Invoke(ProfileManager.Instance.ActiveProfile.DeviceToken); printerProfileData = results; if (printerProfileData != null) { loadingText.Visible = false; List <DateTime> sourceTimes = new List <DateTime>(); foreach (var printerProfile in results.OrderByDescending(d => d.Key)) { // AppEngine results are current in the form of: "2016-07-21 00:43:30.965830" sourceTimes.Add(Convert.ToDateTime(printerProfile.Key).ToLocalTime()); } var groupedTimes = RelativeTime.GroupTimes(DateTime.Now, sourceTimes); FlowLayoutWidget topToBottomStuff = new FlowLayoutWidget(FlowDirection.TopToBottom); scrollWindow.AddChild(topToBottomStuff); foreach (var group in groupedTimes) { // add in the group header topToBottomStuff.AddChild(new TextWidget(RelativeTime.BlockDescriptions[group.Key], textColor: ActiveTheme.Instance.PrimaryTextColor) { Margin = new BorderDouble(0, 0, 0, 5), }); foreach (var time in group.Value) { // add in the radio buttons var profileVersionButton = new RadioButton(time.Value, textColor: ActiveTheme.Instance.PrimaryTextColor) { Margin = new BorderDouble(5, 0), }; profileVersionButton.Checked = false; radioButtonList.Add(profileVersionButton); topToBottomStuff.AddChild(profileVersionButton); } } foreach (var printerProfile in results) { orderedProfiles.Add(printerProfile.Key.ToString()); } } else { loadingText.Text = "Failed To Download History!"; loadingText.TextColor = RGBA_Bytes.Red; } //remove loading profile text/icon }
// Token: 0x0600072E RID: 1838 RVA: 0x00011E18 File Offset: 0x00010E18 public int Add(int value, RelativeTime type) { return(base.Add(new TimeOffset { Value = value, Type = type })); }
public int Add(int value, RelativeTime type) { TimeOffset offset = new TimeOffset { Value = value, Type = type }; return(base.Add(offset)); }
/// <summary> /// Adds a new offset to the collection. /// </summary> /// <param name="value">The offset value.</param> /// <param name="type">The offset type.</param> public int Add(int value, RelativeTime type) { TimeOffset offset = new TimeOffset(); offset.Value = value; offset.Type = type; return(base.Add(offset)); }
public Time(string time) { this.m_absoluteTime = DateTime.MinValue; this.m_baseTime = RelativeTime.Now; this.m_offsets = new TimeOffsetCollection(); Time time2 = Parse(time); this.m_absoluteTime = DateTime.MinValue; this.m_baseTime = time2.m_baseTime; this.m_offsets = time2.m_offsets; }
/// <summary> /// Localize <see cref="RelativeTime"/>. This is meant to emulate how MomentJs allows localization of RelativeTime /// </summary> /// <param name="relativeTime"><see cref="RelativeTime"/></param> /// <param name="number">Difference amount</param> /// <param name="showSuffix">Should suffix? e.g. "ago"</param> /// <param name="isFuture">Difference is in the future or not. e.g. Yesterday vs Tomorrow</param> /// <returns>Localized realtive time e.g.: 5 seconds ago</returns> public string Translate(RelativeTime relativeTime, int number, bool showSuffix, bool isFuture) { var results = string.Empty; switch (relativeTime) { case RelativeTime.Seconds: results = "a few seconds"; break; case RelativeTime.Minute: results = "a minute"; break; case RelativeTime.Minutes: results = string.Format("{0} minutes", number); break; case RelativeTime.Hour: results = "an hour"; break; case RelativeTime.Hours: results = string.Format("{0} hours", number); break; case RelativeTime.Day: results = "a day"; break; case RelativeTime.Days: results = string.Format("{0} days", number); break; case RelativeTime.Month: results = "a month"; break; case RelativeTime.Months: results = string.Format("{0} months", number); break; case RelativeTime.Year: results = "a year"; break; case RelativeTime.Years: results = string.Format("{0} years", number); break; } return(!showSuffix ? results : string.Format(isFuture ? "in {0}" : "{0} ago", results)); }
/// <summary> /// Localize <see cref="RelativeTime"/>. This is meant to emulate how MomentJs allows localization of RelativeTime /// </summary> /// <param name="relativeTime"><see cref="RelativeTime"/></param> /// <param name="number">Difference amount</param> /// <param name="showSuffix">Should suffix? e.g. "ago"</param> /// <param name="isFuture">Difference is in the future or not. e.g. Yesterday vs Tomorrow</param> /// <returns>Localized realtive time e.g.: 5 seconds ago</returns> public string Translate(RelativeTime relativeTime, int number, bool showSuffix, bool isFuture) { var results = string.Empty; switch (relativeTime) { case RelativeTime.Seconds: results = "几秒"; break; case RelativeTime.Minute: results = "1 分钟"; break; case RelativeTime.Minutes: results = string.Format("{0} 分钟", number); break; case RelativeTime.Hour: results = "1 小时"; break; case RelativeTime.Hours: results = string.Format("{0} 小时", number); break; case RelativeTime.Day: results = "1 天"; break; case RelativeTime.Days: results = string.Format("{0} 天", number); break; case RelativeTime.Month: results = "1 个月"; break; case RelativeTime.Months: results = string.Format("{0} 个月", number); break; case RelativeTime.Year: results = "1 年"; break; case RelativeTime.Years: results = string.Format("{0} 年", number); break; } return(!showSuffix ? results : string.Format(isFuture ? "{0}内" : "{0}前", results)); }
/// <summary> /// Localize <see cref="RelativeTime"/>. This is meant to emulate how MomentJs allows localization of RelativeTime /// </summary> /// <param name="relativeTime"><see cref="RelativeTime"/></param> /// <param name="number">Difference amount</param> /// <param name="showSuffix">Should suffix? e.g. "ago"</param> /// <param name="isFuture">Difference is in the future or not. e.g. Yesterday vs Tomorrow</param> /// <returns>Localized realtive time e.g.: 5 seconds ago</returns> public string Translate(RelativeTime relativeTime, int number, bool showSuffix, bool isFuture) { var results = string.Empty; switch (relativeTime) { case RelativeTime.Seconds: results = "quelques secondes"; break; case RelativeTime.Minute: results = "une minute"; break; case RelativeTime.Minutes: results = string.Format("{0} minutes", number); break; case RelativeTime.Hour: results = "une heure"; break; case RelativeTime.Hours: results = string.Format("{0} houres", number); break; case RelativeTime.Day: results = "un jour"; break; case RelativeTime.Days: results = string.Format("{0} jours", number); break; case RelativeTime.Month: results = "un mois"; break; case RelativeTime.Months: results = string.Format("{0} mois", number); break; case RelativeTime.Year: results = "un an"; break; case RelativeTime.Years: results = string.Format("{0} an", number); break; } return(!showSuffix ? results : string.Format(isFuture ? "dans {0}" : "il y a {0}", results)); }
/// <summary> /// Localize <see cref="RelativeTime"/>. This is meant to emulate how MomentJs allows localization of RelativeTime /// </summary> /// <param name="relativeTime"><see cref="RelativeTime"/></param> /// <param name="number">Difference amount</param> /// <param name="showSuffix">Should suffix? e.g. "ago"</param> /// <param name="isFuture">Difference is in the future or not. e.g. Yesterday vs Tomorrow</param> /// <returns>Localized realtive time e.g.: 5 seconds ago</returns> public string Translate(RelativeTime relativeTime, int number, bool showSuffix, bool isFuture) { var results = string.Empty; switch (relativeTime) { case RelativeTime.Seconds: results = "ein paar Sekunden"; break; case RelativeTime.Minute: results = showSuffix ? "einer Minute" : "eine Minute"; break; case RelativeTime.Minutes: results = string.Format("{0} Minuten", number); break; case RelativeTime.Hour: results = showSuffix ? "einer Stunde" : "eine Stunde"; break; case RelativeTime.Hours: results = string.Format("{0} Stunden", number); break; case RelativeTime.Day: results = showSuffix ? "einem Tag" : "ein Tag"; break; case RelativeTime.Days: results = string.Format("{0} {1}", number, showSuffix ? "Tagen" : "Tage"); break; case RelativeTime.Month: results = showSuffix ? "einem Monat" : "ein Monat"; break; case RelativeTime.Months: results = string.Format("{0} {1}", number, showSuffix ? "Monaten" : "Monate"); break; case RelativeTime.Year: results = showSuffix ? "einem Jahr" : "ein Jahr"; break; case RelativeTime.Years: results = string.Format("{0} {1}", number, showSuffix ? "Jahren" : "Jahre"); break; } return(!showSuffix ? results : string.Format(isFuture ? "in {0}" : "vor {0}", results)); }
// Token: 0x06000737 RID: 1847 RVA: 0x00012080 File Offset: 0x00011080 private static TimeOffset CreateOffset(bool positive, int magnitude, string units) { foreach (object obj in Enum.GetValues(typeof(RelativeTime))) { RelativeTime relativeTime = (RelativeTime)obj; if (relativeTime != RelativeTime.Now && units == TimeOffset.OffsetTypeToString(relativeTime)) { return(new TimeOffset { Value = (positive ? magnitude : (-magnitude)), Type = relativeTime }); } } throw new ArgumentOutOfRangeException("units", units, "String is not a valid offset time type."); }
/// <summary> /// Localize <see cref="RelativeTime"/>. This is meant to emulate how MomentJs allows localization of RelativeTime /// </summary> /// <param name="relativeTime"><see cref="RelativeTime"/></param> /// <param name="number">Difference amount</param> /// <param name="showSuffix">Should suffix? e.g. "ago"</param> /// <param name="isFuture">Difference is in the future or not. e.g. Yesterday vs Tomorrow</param> /// <returns>Localized realtive time e.g.: 5 seconds ago</returns> public string Translate(RelativeTime relativeTime, int number, bool showSuffix, bool isFuture) { var results = string.Empty; switch (relativeTime) { case RelativeTime.Seconds: results = "幾秒"; break; case RelativeTime.Minute: results = "1 分鐘"; break; case RelativeTime.Minutes: results = string.Format("{0} 分鐘", number); break; case RelativeTime.Hour: results = "1 小時"; break; case RelativeTime.Hours: results = string.Format("{0} 小時", number); break; case RelativeTime.Day: results = "1 天"; break; case RelativeTime.Days: results = string.Format("{0} 天", number); break; case RelativeTime.Month: results = "1 個月"; break; case RelativeTime.Months: results = string.Format("{0} 個月", number); break; case RelativeTime.Year: results = "1 年"; break; case RelativeTime.Years: results = string.Format("{0} 年", number); break; } return !showSuffix ? results : string.Format(isFuture ? "{0}内" : "{0}前", results); }
/// <summary> /// Localize <see cref="RelativeTime"/>. This is meant to emulate how MomentJs allows localization of RelativeTime /// </summary> /// <param name="relativeTime"><see cref="RelativeTime"/></param> /// <param name="number">Difference amount</param> /// <param name="showSuffix">Should suffix? e.g. "ago"</param> /// <param name="isFuture">Difference is in the future or not. e.g. Yesterday vs Tomorrow</param> /// <returns>Localized realtive time e.g.: 5 seconds ago</returns> public string Translate(RelativeTime relativeTime, int number, bool showSuffix, bool isFuture) { var results = string.Empty; switch (relativeTime) { case RelativeTime.Seconds: results = "ein paar Sekunden"; break; case RelativeTime.Minute: results = showSuffix ? "einer Minute" : "eine Minute"; break; case RelativeTime.Minutes: results = string.Format("{0} Minuten", number); break; case RelativeTime.Hour: results = showSuffix ? "einer Stunde" : "eine Stunde"; break; case RelativeTime.Hours: results = string.Format("{0} Stunden", number); break; case RelativeTime.Day: results = showSuffix ? "einem Tag" : "ein Tag"; break; case RelativeTime.Days: results = string.Format("{0} {1}", number, showSuffix ? "Tagen" : "Tage"); break; case RelativeTime.Month: results = showSuffix ? "einem Monat" : "ein Monat"; break; case RelativeTime.Months: results = string.Format("{0} {1}", number, showSuffix ? "Monaten" : "Monate"); break; case RelativeTime.Year: results = showSuffix ? "einem Jahr" : "ein Jahr"; break; case RelativeTime.Years: results = string.Format("{0} {1}", number, showSuffix ? "Jahren" : "Jahre"); break; } return !showSuffix ? results : string.Format(isFuture ? "in {0}" : "vor {0}", results); }
/// <summary> /// Localize <see cref="RelativeTime"/>. This is meant to emulate how MomentJs allows localization of RelativeTime /// </summary> /// <param name="relativeTime"><see cref="RelativeTime"/></param> /// <param name="number">Difference amount</param> /// <param name="showSuffix">Should suffix? e.g. "ago"</param> /// <param name="isFuture">Difference is in the future or not. e.g. Yesterday vs Tomorrow</param> /// <returns>Localized realtive time e.g.: 5 seconds ago</returns> public string Translate(RelativeTime relativeTime, int number, bool showSuffix, bool isFuture) { var results = string.Empty; switch (relativeTime) { case RelativeTime.Seconds: results = "a few seconds"; break; case RelativeTime.Minute: results = "a minute"; break; case RelativeTime.Minutes: results = string.Format("{0} minutes", number); break; case RelativeTime.Hour: results = "an hour"; break; case RelativeTime.Hours: results = string.Format("{0} hours", number); break; case RelativeTime.Day: results = "a day"; break; case RelativeTime.Days: results = string.Format("{0} days", number); break; case RelativeTime.Month: results = "a month"; break; case RelativeTime.Months: results = string.Format("{0} months", number); break; case RelativeTime.Year: results = "a year"; break; case RelativeTime.Years: results = string.Format("{0} years", number); break; } return !showSuffix ? results : string.Format(isFuture ? "in {0}" : "{0} ago", results); }
// GET: Tickets/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Ticket ticket = db.Tickets.Find(id); if (ticket == null) { return(HttpNotFound()); } var userId = User.Identity.GetUserId(); if (!URManager.UserIsInRole(userId, "Administrator")) { if (!(ticket.Project.InChargeOfId == userId)) { if (!(ticket.AssignedToId == userId)) { if (!(ticket.SubmitterId == userId)) { return(RedirectToAction("Login", "Account")); } } } } if (ticket.TicketStatus.Name == "Resolved" && !User.IsInRole("Administrator")) { return(RedirectToAction("Login", "Account")); } ViewBag.NumberOfComments = ticket.TicketComments.Count; //definitely a better way to do this part. doesn't need to be stored in a database RelativeTime relativeTime = new RelativeTime(); if (ticket.TicketComments != null && ticket.TicketComments.Any()) { foreach (var comment in ticket.TicketComments) { comment.TimeSincePosted = relativeTime.TimeAgo(comment.Created); db.Entry(comment).Property("TimeSincePosted").IsModified = true; db.SaveChanges(); } } ViewBag.NumberOfAttachments = ticket.TicketAttachments.Count; if (ticket.TicketAttachments != null && ticket.TicketAttachments.Any()) { foreach (var attachment in ticket.TicketAttachments) { attachment.TimeSincePosted = relativeTime.TimeAgo(attachment.Created); db.Entry(attachment).Property("TimeSincePosted").IsModified = true; db.SaveChanges(); } } ViewBag.NumberOfChanges = ticket.TicketHistoryEvents.Count - 4; TicketHistoryViewModel vm = new TicketHistoryViewModel(); vm.Ticket = ticket; vm.CreatedBy = db.Users.Find(ticket.TicketHistoryEvents.ToList()[0].UserId); vm.CreatedId = ticket.TicketHistoryEvents.ToList()[0].NewValue; vm.CreatedDescription = ticket.TicketHistoryEvents.ToList()[1].NewValue; vm.CreatedPriority = ticket.TicketHistoryEvents.ToList()[2].NewValue; vm.CreatedStatus = ticket.TicketHistoryEvents.ToList()[3].NewValue; return(View(vm)); }
internal RangeAggregator(string name, int value, TimeUnit timeUnit) { Name = name; Sampling = new RelativeTime(value, timeUnit); }
public override string ToString() => RelativeTime.ToString(CultureInfo.InvariantCulture);
public override string ToString() => $"{RelativeTime.ToString(CultureInfo.InvariantCulture)} {Type} {FrameId}";
public ActionResult PMDashboard() { if (User.IsInRole("Administrator")) { return(RedirectToAction("AdminDashboard")); } var currentUserId = User.Identity.GetUserId(); var currentUser = db.Users.Find(currentUserId); //Finding tickets this user has access to var projects = db.Projects.Where(p => p.InChargeOfId == currentUser.Id).Select(p => p.Id).AsEnumerable(); var permissionTickets = db.Tickets.Where(t => (projects.Contains(t.ProjectId) || t.AssignedToId == currentUserId || t.SubmitterId == currentUserId) && t.TicketStatus.Name != "Resolved").ToList(); //Start ViewBags for Dashboard Count Values ViewBag.HighPriorityTicketsCount = permissionTickets.Where(t => t.TicketPriority.Name == "High").Count(); var changeCount = 0; foreach (var ticket in permissionTickets.ToList()) { changeCount += ticket.TicketHistoryEvents.Where(th => th.ChangedDate > DateTimeOffset.Now.AddDays(-7)).ToList().Count(); } ViewBag.RecentChangesCount = changeCount; var inChargeOfTickets = permissionTickets.Where(t => projects.Contains(t.ProjectId)).ToList(); var assignedTickets = inChargeOfTickets.Where(t => t.TicketStatus.Name == "Assigned"); var assignCount = 0; foreach (var ticket in assignedTickets) { var mostRecentAssignment = ticket.TicketHistoryEvents.Reverse().FirstOrDefault(th => th.NewValue == "Assigned"); var timeComparison = DateTimeOffset.Compare(mostRecentAssignment.ChangedDate, DateTimeOffset.Now.AddDays(-7)); if (timeComparison > 0) { assignCount++; } } ViewBag.RecentlyAssignedTicketsCount = assignCount; //Start ViewModel DashboardViewModel model = new DashboardViewModel(); //Start Tickets for ViewModel model.Tickets = inChargeOfTickets.Where(t => t.TicketStatus.Name == "Unassigned").ToList(); //Start Projects for ViewModel model.Projects = currentUser.Projects.ToList(); //Start TicketComments for ViewModel var pt = permissionTickets.Select(t => t.Id).AsEnumerable(); var permissionComments = db.TicketComments.Where(tc => pt.Contains(tc.TicketId)).ToList(); model.TicketComments = permissionComments.Where(tc => tc.Created > DateTimeOffset.Now.AddDays(-2)).ToList(); RelativeTime relativeTime = new RelativeTime(); if (model.TicketComments != null && model.TicketComments.Any()) { foreach (var comment in model.TicketComments) { comment.TimeSincePosted = relativeTime.TimeAgo(comment.Created); db.Entry(comment).Property("TimeSincePosted").IsModified = true; db.SaveChanges(); } } //Start TicketAttachments for ViewModel var permissionAttachments = db.TicketAttachments.Where(ta => pt.Contains(ta.TicketId)).ToList(); model.TicketAttachments = permissionAttachments.Where(ta => ta.Created > DateTimeOffset.Now.AddDays(-2)).ToList(); if (model.TicketAttachments != null && model.TicketAttachments.Any()) { foreach (var attachment in model.TicketAttachments) { attachment.TimeSincePosted = relativeTime.TimeAgo(attachment.Created); db.Entry(attachment).Property("TimeSincePosted").IsModified = true; db.SaveChanges(); } } return(View(model)); }
public ActionResult SubmitterDashboard() { if (User.IsInRole("Administrator")) { return(RedirectToAction("AdminDashboard")); } if (User.IsInRole("Project Manager")) { return(RedirectToAction("PMDashboard")); } if (User.IsInRole("Developer")) { return(RedirectToAction("DeveloperDashboard")); } var currentUserId = User.Identity.GetUserId(); var currentUser = db.Users.Find(currentUserId); //Finding tickets this user has access to var permissionTickets = new List <Ticket>(); permissionTickets = db.Tickets.Where(t => t.SubmitterId == currentUserId && t.TicketStatus.Name != "Resolved").ToList(); //Start ViewBags for Dashboard Count Values ViewBag.HighPriorityTicketsCount = permissionTickets.Where(t => t.TicketPriority.Name == "High").Count(); var changeCount = 0; foreach (var ticket in permissionTickets.ToList()) { changeCount += ticket.TicketHistoryEvents.Where(th => th.ChangedDate > DateTimeOffset.Now.AddDays(-7)).ToList().Count(); } ViewBag.RecentChangesCount = changeCount; //Start ViewModel DashboardViewModel model = new DashboardViewModel(); //Start Tickets for ViewModel model.Tickets = permissionTickets.Where(t => t.TicketPriority.Name == "High").ToList(); //Start Projects for ViewModel model.Projects = currentUser.Projects.ToList(); //Start TicketComments for ViewModel var pt = permissionTickets.Select(t => t.Id).AsEnumerable(); var permissionComments = db.TicketComments.Where(tc => pt.Contains(tc.TicketId)).ToList(); model.TicketComments = permissionComments.Where(tc => tc.Created > DateTimeOffset.Now.AddDays(-2)).ToList(); RelativeTime relativeTime = new RelativeTime(); if (model.TicketComments != null && model.TicketComments.Any()) { foreach (var comment in model.TicketComments) { comment.TimeSincePosted = relativeTime.TimeAgo(comment.Created); db.Entry(comment).Property("TimeSincePosted").IsModified = true; db.SaveChanges(); } } //Start TicketAttachments for ViewModel var permissionAttachments = db.TicketAttachments.Where(ta => pt.Contains(ta.TicketId)).ToList(); model.TicketAttachments = permissionAttachments.Where(ta => ta.Created > DateTimeOffset.Now.AddDays(-2)).ToList(); if (model.TicketAttachments != null && model.TicketAttachments.Any()) { foreach (var attachment in model.TicketAttachments) { attachment.TimeSincePosted = relativeTime.TimeAgo(attachment.Created); db.Entry(attachment).Property("TimeSincePosted").IsModified = true; db.SaveChanges(); } } return(View(model)); }
public ActionResult AdminDashboard() { var currentUserId = User.Identity.GetUserId(); var currentUser = db.Users.Find(currentUserId); //Start ViewBags for Dashboard Count Values ViewBag.HighPriorityTicketsCount = db.Tickets.Where(t => t.TicketPriority.Name == "High").Count(); var resolvedTickets = db.Tickets.Where(t => t.TicketStatus.Name == "Resolved"); var resolvedCount = 0; foreach (var ticket in resolvedTickets.ToList()) { var mostRecentHistory = ticket.TicketHistoryEvents.Reverse().FirstOrDefault(th => th.NewValue == "Resolved"); var timeComparison = DateTimeOffset.Compare(mostRecentHistory.ChangedDate, DateTimeOffset.Now.AddDays(-7)); if (timeComparison > 0) { resolvedCount++; } } ViewBag.RecentlyResolvedCount = resolvedCount; var changeCount = 0; foreach (var ticket in db.Tickets.ToList()) { changeCount += ticket.TicketHistoryEvents.Where(th => th.ChangedDate > DateTimeOffset.Now.AddDays(-7)).ToList().Count(); } ViewBag.RecentChangesCount = changeCount; var assignedTickets = db.Tickets.Where(t => t.TicketStatus.Name == "Assigned"); var assignCount = 0; foreach (var ticket in assignedTickets) { var mostRecentAssignment = ticket.TicketHistoryEvents.Reverse().FirstOrDefault(th => th.NewValue == "Assigned"); var timeComparison = DateTimeOffset.Compare(mostRecentAssignment.ChangedDate, DateTimeOffset.Now.AddDays(-7)); if (timeComparison > 0) { assignCount++; } } ViewBag.RecentlyAssignedTicketsCount = assignCount; //Start ViewModel DashboardViewModel model = new DashboardViewModel(); //Start Tickets for ViewModel model.Tickets = db.Tickets.Where(t => t.TicketStatus.Name == "Unassigned").ToList(); //Start Projects for ViewModel model.Projects = currentUser.Projects.ToList(); //Start TicketComments for ViewModel model.TicketComments = db.TicketComments.ToList().Where(tc => tc.Created > DateTimeOffset.Now.AddDays(-2)).ToList(); RelativeTime relativeTime = new RelativeTime(); if (model.TicketComments != null && model.TicketComments.Any()) { foreach (var comment in model.TicketComments) { comment.TimeSincePosted = relativeTime.TimeAgo(comment.Created); db.Entry(comment).Property("TimeSincePosted").IsModified = true; db.SaveChanges(); } } //Start TicketAttachments for ViewModel model.TicketAttachments = db.TicketAttachments.ToList().Where(ta => ta.Created > DateTimeOffset.Now.AddDays(-2)).ToList(); if (model.TicketAttachments != null && model.TicketAttachments.Any()) { foreach (var attachment in model.TicketAttachments) { attachment.TimeSincePosted = relativeTime.TimeAgo(attachment.Created); db.Entry(attachment).Property("TimeSincePosted").IsModified = true; db.SaveChanges(); } } return(View(model)); }
public void RelativeFriendlyDatesTest() { { // May 28, 2016 at 3:13 pm DateTime nowTime = new DateTime(2016, 05, 28, 15, 13, 37); DateTime testTime = nowTime.AddMinutes(-63); Assert.IsTrue(RelativeTime.GetTimeBlock(nowTime, testTime) == TimeBlock.Today); Assert.IsTrue(RelativeTime.GetDetail(nowTime, testTime) == "2:10 PM"); testTime = nowTime.AddHours(-25); Assert.IsTrue(RelativeTime.GetTimeBlock(nowTime, testTime) == TimeBlock.Yesterday); Assert.IsTrue(RelativeTime.GetDetail(nowTime, testTime) == "2:13 PM"); testTime = nowTime.AddDays(-4); Assert.IsTrue(RelativeTime.GetTimeBlock(nowTime, testTime) == TimeBlock.SameWeek); Assert.IsTrue(RelativeTime.GetDetail(nowTime, testTime) == "Tuesday 3:13 PM"); testTime = nowTime.AddDays(-6); Assert.IsTrue(RelativeTime.GetTimeBlock(nowTime, testTime) == TimeBlock.SameWeek); Assert.IsTrue(RelativeTime.GetDetail(nowTime, testTime) == "Sunday 3:13 PM"); testTime = nowTime.AddDays(-7); Assert.IsTrue(RelativeTime.GetTimeBlock(nowTime, testTime) == TimeBlock.SameMonth); Assert.IsTrue(RelativeTime.GetDetail(nowTime, testTime) == "May 21, 3:13 PM"); testTime = nowTime.AddDays(-37); Assert.IsTrue(RelativeTime.GetTimeBlock(nowTime, testTime) == TimeBlock.SameYear); Assert.IsTrue(RelativeTime.GetDetail(nowTime, testTime) == "April 21, 3:13 PM"); testTime = nowTime.AddDays(-364); Assert.IsTrue(RelativeTime.GetTimeBlock(nowTime, testTime) == TimeBlock.PastYear); Assert.IsTrue(RelativeTime.GetDetail(nowTime, testTime) == "2015 May 30, 3:13 PM"); } // make a grouped list { // May 28, 2016 at 3:13 pm DateTime nowTime = new DateTime(2016, 05, 28, 15, 13, 37); List <DateTime> allTimes = new List <DateTime>() { nowTime.AddMinutes(-63), nowTime.AddMinutes(-82), nowTime.AddHours(-25), nowTime.AddHours(-31), nowTime.AddDays(-4), nowTime.AddDays(-6), nowTime.AddDays(-7), nowTime.AddDays(-37), nowTime.AddDays(-364), }; var orderedForDisplay = RelativeTime.GroupTimes(nowTime, allTimes); Assert.IsTrue(orderedForDisplay.Count == 6); Assert.IsTrue(orderedForDisplay[TimeBlock.Today].Count == 2); Assert.IsTrue(orderedForDisplay[TimeBlock.Yesterday].Count == 2); Assert.IsTrue(orderedForDisplay[TimeBlock.SameWeek].Count == 2); Assert.IsTrue(orderedForDisplay[TimeBlock.SameMonth].Count == 1); Assert.IsTrue(orderedForDisplay[TimeBlock.SameYear].Count == 1); Assert.IsTrue(orderedForDisplay[TimeBlock.PastYear].Count == 1); } }