public void init() { //base.TestInitialise(); w = new DefaultSicknessWorkflow(SicknessWorkflowConfiguration.GetDefault()); }
/// <summary> /// Create a new sickness absence /// </summary> /// <param name="data"></param> /// <returns></returns> public JsonResult Create(SicknessAbsenceViewModel data) { if (ModelState.IsValid) { using (var orgSession = OrgStore.OpenSession()) { var classification = orgSession.Query<SicknessClassification>().FirstOrDefault(); var subject = orgSession.Load<User>(data.UserId); var reason = classification.GetReason(data.SicknessReasonId); var sickness = new Sickness { Subject = subject.ToSimpleUser(), SicknessReason = SicknessReasonSimple.Create(reason), StartOfProcess = data.StartOfProcess, EndOfProcess = data.EndOfProcess, ConsolidatedCompletionDate = data.EndOfProcess ?? DateTime.Now, Title = data.Title, Summary = data.Summary, UserCreatedProcess = OrgUser.ToSimpleUser(), CurrentProcessOwner = OrgUser.ToSimpleUser(), //TODO: What if self created? Should be manager. Id = IlluminateDatabase.GenerateId<Sickness>() }; orgSession.Store(sickness); //update the user state. if (sickness.StartOfProcess.Date <= DateTime.Today && sickness.ConsolidatedCompletionDate.Date >= DateTime.Today) { subject.CurrentState = "onsick"; } //get the workflow config var config = SicknessWorkflowConfiguration.Generate(orgSession); //definition should already exist //create a new default sickness workflow and assign it to the sickness var workflow = new DefaultSicknessWorkflow(config); sickness.Workflow = workflow; //handle the created event of the sickness sickness.HandleEvent(OrgStore,"Sickness", "Create", sickness); orgSession.SaveChanges(); return JsonSuccess(sickness.ToTimelineItems(), "Sickness item created"); } } return JsonError("Invalid data: " + ViewData.ModelState.Values.Any(x => x.Errors.Count >= 1)); }