public HttpResponseMessage RemoveHoliday(string name, int holidayId, IEnumerable <string> dates) { try { //1. search if exist wf var workflows = TasksService.SearchWorkflows(new SearchWorkflowsRequest { Domain = string.Empty, WorkflowCode = "HolidayWf", Properties = new PropertyInfos(new List <PropertyInfo> { new PropertyInfo { Name = "UserName", Value = name }, new PropertyInfo { Name = "HolidayId", Value = holidayId.ToString() } }) }); if (workflows.WorkflowInfos.Any()) { //2. If workflow in progress terminate if (workflows.WorkflowInfos[0].Status == WorkflowStatusType.InProgress.ToString()) { var resp = TasksService.CancelWorkflow(new ControlWorkflowRequest { WorkflowOid = workflows.WorkflowInfos[0].WorkflowId }); } else { //3. else start a new wf or send a notification TasksService.CreateNotification(new CreateNotificationRequest { NotificationInfo = new NotificationInfo { AssignedToUsers = "{r.HR}", TaskOid = Guid.NewGuid(), WorkflowOid = Guid.Parse(workflows.WorkflowInfos[0].WorkflowId), Title = string.Format("Holiday cancellation for user {0}", name), Description = string.Format("The holiday previously requested by user {0} has been cancelled. Holiday details: {1}", name, string.Join(",", dates)) } }); } } var removeHoliday = TasksService.RemoveHoliday(new RemoveHolidayRequest { HolidayId = holidayId, User = name }); if (!removeHoliday.IsRemoved) { var result = Request.CreateResponse(HttpStatusCode.InternalServerError); result.Content = new StringContent("Could not remove workflow. Contact System Administrator.", Encoding.UTF8, "text/plain"); return(result); } return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage Operations([FromBody] IEnumerable <string> woids, string op) { var messages = new List <ErrorMessage>(); if (op == WorkflowOperation.Delete.ToString()) { foreach (var o in woids) { var resp = TasksService.DeleteWorkflow(new ControlWorkflowRequest { WorkflowOid = o }); if (resp.Message != "OK") { messages.Add(new ErrorMessage { Id = o, Message = resp.Message }); } } } if (op == WorkflowOperation.Restart.ToString()) { foreach (var o in woids) { var resp = TasksService.ReStartWorkflow(new ReStartWorkflowRequest { OldWorkflowId = o }); if (resp.Message != "OK") { messages.Add(new ErrorMessage { Id = o, Message = resp.Message }); } } } if (op == WorkflowOperation.Terminate.ToString()) { foreach (var o in woids) { var resp = TasksService.CancelWorkflow(new ControlWorkflowRequest { WorkflowOid = o }); if (resp.Message != "OK") { messages.Add(new ErrorMessage { Id = o, Message = resp.Message }); } } } var json = JsonConvert.SerializeObject( messages, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); var result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new StringContent(json, Encoding.UTF8, "text/plain"); return(result); }