Ejemplo n.º 1
0
 public Models.Ribbit Create(int userId, string status, DateTime? created = null)
 {
     var ribbit = new Ribbit()
     {
         AuthorId = userId,
         Status = status,
         DateCreated = created.HasValue ? created.Value : DateTime.Now
     };
     _ribbits.Create(ribbit);
     _context.SaveChanges();
     return ribbit;
 }
Ejemplo n.º 2
0
        public static string FriendlyTimestamp(this Ribbit ribbit)
        {
            var now  = DateTime.Now;
            var date = ribbit.DateCreated;
            var span = now - date;

            if (span > TimeSpan.FromHours(24))
            {
                return(date.ToString("MMM dd"));
            }
            if (span > TimeSpan.FromMinutes(60))
            {
                return(string.Format("{0}h", span.Hours));
            }
            if (span > TimeSpan.FromSeconds(60))
            {
                return(string.Format("{0}m", span.Minutes));
            }
            return("Now");
        }