public ActionResult Capture(HIGCaptureViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newHigEntry = HIGHelper.Capture(OrgStore, (User) OrgUser, model);
                SaveOrgUserAsClaim();

                return Json(newHigEntry.ToTimelineItems());
            }
            return JsonError("Invalid Hig");
        }
        public static HIGEntry Capture(IDocumentStore store, User user, HIGCaptureViewModel model)
        {
            using (var orgSession = store.OpenSession())
            {
                var simpleUser = user.ToSimpleUser();
            
                var hv = new HIGEntry
                {
                    CaptureDate = DateTime.Now,
                    ConsolidatedCompletionDate = DateTime.Now,
                    Subject = simpleUser,
                    Value = model.HIGValue,
                    Message = model.HIGMessage,
                    Id = IlluminateDatabase.GenerateId<HIGEntry>(),
                    LastInDay = true
                };

                if (user.LatestHig != null && user.LatestHig.CaptureDate.Date == DateTime.UtcNow.Date) //same day
                {
                    //previous hig should be not latest in day. 
                    var lasthig = orgSession.Load<HIGEntry>(user.LatestHig.Id);
                    lasthig.LastInDay = false; 
                }

                //set users latest hig. 
                user.LatestHig = hv;

                if (hv.Value < 0)
                {
                    //alert! Alert!

                    var notify = new Notification
                    {
                        About = simpleUser,
                        Body =
                            String.Format(
                                "{0} added a new negative HIG on {1}. Perhaps you should investigate",
                                user.Name, hv.CaptureDate),
                        SendDate = DateTime.Now,
                        Title = string.Format("HIG Alert for {0}", user.Name),
                        From = EmailRecipient.GetIlluminateRecipient(),
                        NotificationRecipients = new[]
                                                                          {
                                                                              new NotificationRecipient
                                                                                  {

                                                                                      NotificationDeliveryTypes =
                                                                                          NotificationDeliveryTypes
                                                                                              .Toast |
                                                                                          NotificationDeliveryTypes
                                                                                              .Email |
                                                                                              NotificationDeliveryTypes.Sms
                                                                                              ,
                                                                                      
                                                                                      Users = user.Relationships
                                                                                      .Where(r => r.RelationshipName == Role.BuiltInRole.LineManager.ToString() )

                                                                                  }
                                                                          },
                    };
                    orgSession.Store(notify);
                }


                orgSession.Store(user);
                orgSession.Store(hv);
                orgSession.SaveChanges();

                return hv; 
            }
        }