| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using Comal.Classes;
 
- using InABox.Core;
 
- using InABox.Database;
 
- namespace Comal.Stores
 
- {
 
-     public class UserPlatform
 
-     {
 
-         public string UserID { get; set; }
 
-         public string Platform { get; set; }
 
-         public string Version { get; set; }
 
-     }
 
-     public static class PlatformCache
 
-     {
 
-         static PlatformCache()
 
-         {
 
-             Platforms = new List<UserPlatform>();
 
-         }
 
-         public static List<UserPlatform> Platforms { get; }
 
-     }
 
-     public class BaseStore<T> : Store<T> where T : Entity, new()
 
-     {
 
-         protected override Filter<T> PrepareFilter(Filter<T> filter)
 
-         {
 
-             CheckPlatformVersion();
 
-             return base.PrepareFilter(filter);
 
-         }
 
-         protected override void BeforeSave(T entity)
 
-         {
 
-             CheckPlatformVersion();
 
-             base.BeforeSave(entity);
 
-         }
 
-         protected override void BeforeDelete(T entity)
 
-         {
 
-             CheckPlatformVersion();
 
-             base.BeforeDelete(entity);
 
-         }
 
-         private void CheckPlatformVersion()
 
-         {
 
-             if (string.IsNullOrEmpty(UserID) || string.IsNullOrEmpty(Platform) || string.IsNullOrEmpty(Version))
 
-                 return;
 
-             var platform = PlatformCache.Platforms.FirstOrDefault(x => x.UserID.Equals(UserID) && x.Platform.Equals(Platform));
 
-             if (platform == null)
 
-             {
 
-                 platform = new UserPlatform { UserID = UserID, Platform = Platform, Version = "???" };
 
-                 PlatformCache.Platforms.Add(platform);
 
-             }
 
-             if (!platform.Version.Equals(Version))
 
-             {
 
-                 platform.Version = Version;
 
-                 var prop = DatabaseSchema.Property(typeof(User), Platform);
 
-                 if (prop != null && prop.Getter() != null && prop.Setter() != null)
 
-                 {
 
-                     var user = Provider.Load(new Filter<User>(x => x.UserID).IsEqualTo(UserID)).FirstOrDefault();
 
-                     if (user != null)
 
-                     {
 
-                         var value = prop.Getter().Invoke(user);
 
-                         if (!Version.Equals(value))
 
-                         {
 
-                             prop.Setter().Invoke(user, Version);
 
-                             Provider.Save(user);
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         
 
-         protected void UnlinkTrackingKanban<TEntityKanban, TEntity, TEntityLink>(TEntity entity)
 
-             where TEntityKanban : EntityKanban<TEntity, TEntityLink>, new()
 
-             where TEntity : Entity
 
-             where TEntityLink : IEntityLink<TEntity>, new()
 
-         {
 
-             var kanbans = Provider.Query(
 
-                 new Filter<TEntityKanban>(x => x.Entity.ID).IsEqualTo(entity.ID).And(x => x.Kanban.Locked).IsEqualTo(true),
 
-                 new Columns<TEntityKanban>(
 
-                     x => x.Entity.ID,
 
-                     x => x.Kanban.ID,
 
-                     x => x.Kanban.Locked
 
-                 )
 
-             );
 
-             if (!kanbans.Rows.Any())
 
-                 return;
 
-             var kanban = kanbans.Rows.First().ToObject<RequisitionKanban, KanbanLink, Kanban>(x => x.Kanban);
 
-             kanban.Locked = false;
 
-             Provider.Save(kanban);
 
-         }
 
-         protected void UpdateTrackingKanban<TEntityKanban, TEntity, TEntityLink>(TEntity entity, Func<TEntity, KanbanCategory> category)
 
-             where TEntityKanban : EntityKanban<TEntity, TEntityLink>, new()
 
-             where TEntity : Entity
 
-             where TEntityLink : IEntityLink<TEntity>, new()
 
-         {
 
-             var kanbans = Provider.Query(
 
-                 new Filter<TEntityKanban>(x => x.Entity.ID).IsEqualTo(entity.ID),
 
-                 new Columns<TEntityKanban>(
 
-                     x => x.Entity.ID,
 
-                     x => x.Kanban.ID,
 
-                     x => x.Kanban.Category,
 
-                     x => x.Kanban.Closed,
 
-                     x => x.Kanban.Completed,
 
-                     x => x.Kanban.EmployeeLink.ID,
 
-                     x => x.Kanban.Notes,
 
-                     x => x.Kanban.DueDate,
 
-                     x => x.Kanban.Title,
 
-                     x => x.Kanban.Summary
 
-                 )
 
-             );
 
-             if (!kanbans.Rows.Any())
 
-                 return;
 
-             var oldcategory = Kanban.StringToCategory(kanbans.Rows.First().Get<TEntityKanban, string>(c => c.Kanban.Category));
 
-             var newcategory = category(entity);
 
-             if (!Equals(newcategory, oldcategory))
 
-             {
 
-                 var kanban = kanbans.Rows.First().ToObject<RequisitionKanban, KanbanLink, Kanban>(x => x.Kanban);
 
-                 kanban.Category = Kanban.CategoryToString(newcategory);
 
-                 var notes = kanban.Notes.ToList();
 
-                 notes.Add(string.Format("{0:yyyy-MM-dd HH:mm:ss} {1}: {2}", DateTime.Now, UserID, "Task Status updated by Requisition Progress"));
 
-                 kanban.Notes = notes.ToArray();
 
-                 kanban.Locked = true;
 
-                 FindSubStore<Kanban>().Save(kanban, "Updated due to Requisition Status Change");
 
-             }
 
-         }
 
-         
 
-         protected void NotifyEmployee<TEntity>(
 
-             TEntity entity,
 
-             Func<TEntity, Guid> employeeid,
 
-             Func<TEntity, bool> filter,
 
-             Func<TEntity, string> title,
 
-             Func<TEntity, string> body
 
-         ) where TEntity : Entity
 
-         {
 
-             if (!filter(entity))
 
-                 return;
 
-             var employees = Provider.Query(
 
-                 new Filter<Employee>(x => x.ID).IsEqualTo(employeeid(entity)).Or(x => x.UserLink.ID).IsEqualTo(UserGuid),
 
-                 new Columns<Employee>(x => x.ID).Add(x => x.UserLink.ID).Add(x => x.Name)
 
-             ).Rows.Select(r => new Tuple<Guid, Guid, string>(
 
-                     r.Get<Employee, Guid>(c => c.ID),
 
-                     r.Get<Employee, Guid>(c => c.UserLink.ID),
 
-                     r.Get<Employee, string>(c => c.Name)
 
-                 )
 
-             );
 
-             var recipient = employees.FirstOrDefault(x => Equals(x.Item1, employeeid(entity)));
 
-             var sender = employees.FirstOrDefault(x => Equals(x.Item2, UserGuid));
 
-             if (recipient == null || sender == null)
 
-                 return;
 
-             if (recipient.Item2 == UserGuid)
 
-                 return;
 
-             var notification = new Notification();
 
-             notification.Employee.ID = recipient.Item1;
 
-             notification.Sender.ID = sender.Item1;
 
-             notification.Title = title(entity);
 
-             var sb = new StringBuilder();
 
-             sb.AppendLine(string.Format("Dear {0},\n", recipient.Item3.Split(' ').First()));
 
-             sb.Append(body.Invoke(entity));
 
-             if (sender != null)
 
-                 sb.AppendLine(string.Format("\n\nRegards,\n{0}.", sender.Item3.Split(' ').First()));
 
-             notification.Description = sb.ToString();
 
-             notification.EntityType = typeof(TEntity).EntityName();
 
-             notification.EntityID = entity.ID;
 
-             FindSubStore<Notification>().Save(notification, "");
 
-         }
 
-     }
 
- }
 
 
  |