public JsonResult Create(LeaveAbsenceViewModel data)
        {
            if (ModelState.IsValid)
            {
                using (var orgSession = OrgStore.OpenSession())
                {
                    var type = orgSession.Load<LeaveType>(data.LeaveTypeId);
                    var subject = orgSession.Load<User>(data.UserId);

                    var leave = new Leave
                                    {
                                        Subject = subject.ToSimpleUser(),
                                        LeaveType = type,
                                        StartOfProcess = data.StartOfProcess,
                                        EndOfProcess = data.EndOfProcess,
                                        ConsolidatedCompletionDate = data.EndOfProcess ?? DateTime.Now,
                                        Title = data.Title,
                                        Summary = data.Summary,
                                        UserCreatedProcess = OrgUser.ToSimpleUser(),
                                        Id = IlluminateDatabase.GenerateId<Leave>(),
                                        Approval = null,
                                        
                                    };


                    //If leave was created by a manager, then approve it already. 
                    if (subject.CanBeManagedBy((User)OrgUser)) //TODO: might be good to return the relationship that caused the approval.
                    {
                        leave.Approval = Approval.CreateApproval(OrgUser.ToSimpleUser());  
                    }

                    //get the workflow config
                    var config = orgSession.Query<LeaveWorkflowConfiguration>().FirstOrDefault();
                    if (config == null)
                    {
                        GetLogger().Error(string.Format("Cannot get sickness config for {0} organisation - no document in database, creating a default", OrgKey));
                        config = LeaveWorkflowConfiguration.GetDefault();
                        orgSession.Store(config);
                        orgSession.SaveChanges();
                    }

                    //create a new default leave workflow and assign to Leave - store it in the DB
                    leave.Workflow = new DefaultLeaveWorkflow(config);
                    orgSession.Store(leave);

                    //update the user state. 
                    if (leave.StartOfProcess.Date <= DateTime.Today && leave.ConsolidatedCompletionDate.Date >= DateTime.Today)
                    {
                        subject.CurrentState = "onleave";
                    }
                    //handle the create leave event
                    leave.HandleEvent(OrgStore, "Leave", "Create", leave);

                    orgSession.SaveChanges();

                    return JsonSuccess(leave.ToTimelineItems(), "Leave item created");
                }
            }

            return JsonError("Invalid data: " + ViewData.ModelState.Values.Any(x => x.Errors.Count >= 1));
        }