public ActionResult Create(TaskFormModel model) { var task = TaskService.TaskNew(); this.MapToObject(model, task); task = TaskService.TaskSave(task); if (task.IsValid) { if (model.HourId != 0) { var hour = HourService.HourFetch(model.HourId); hour.TaskId = task.TaskId; HourService.HourSave(hour); } return(new JsonResult { Data = this.Url.Action("Edit", new { id = task.TaskId, message = Resources.SaveSuccessfulMessage }) }); } this.MapToModel(task, model, false); return(this.View(model)); }
public ActionResult Create(int?hourId) { var model = new TaskFormModel(); try { Task task; if (hourId != null) { task = TaskService.TaskNew(HourService.HourFetch((int)hourId)); } else { task = TaskService.TaskNew(); } this.MapToModel(task, model, true); } catch (Exception ex) { this.ModelState.AddModelError(string.Empty, ex.Message); } return(this.View(model)); }
public async Task <Result <bool> > SubmitTaskFormDataAsync(TaskFormModel taskFormModel) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(base.BaseUrl); HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, RequestUri); requestMessage.Headers.Add("Authorization", base.GetBasicAuthorizationHeaderValue()); string jsonData = JsonConvert.SerializeObject(taskFormModel, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); requestMessage.Content = new StringContent(jsonData, Encoding.UTF8, "application/json"); var response = await client.SendAsync(requestMessage); if (!response.IsSuccessStatusCode) { return(null); } return(Result <bool> .ErrorWhenNoData(true)); } }
private async Task Manager(Models.Conversation.ConversationModel conversation, TaskModel task) { var messagesResult = await _facebbokMessageService.GetConversationMessages(conversation.FacebookConversationId); var messages = messagesResult.Value; string message = messages.FirstOrDefault()?.Message; if (message == null) { return; } TaskFormModel form = new TaskFormModel(); if (message.Trim().Equals("1")) { form = new TaskFormModel { TaskId = task.Id, Properties = new List <TaskFormProperty> { new TaskFormProperty { Id = "status", Value = "logowanie" } } }; } else if (message.Trim().Equals("2")) { form = new TaskFormModel { TaskId = task.Id, Properties = new List <TaskFormProperty> { new TaskFormProperty { Id = "status", Value = "rozmowa" } } }; } var nextTaskResult = await _activitiWorker.CompleteTaskSubmittingFormAndGetNextAsync((int)conversation.ProcessInstanceId, form); var nextTask = nextTaskResult.Value; conversation.ProcessTask = nextTask.ProcessTask; conversation.Messages = null; _conversationService.Update(conversation); await ChangeTask(conversation, nextTask); }
private async Task CheckAdviser(Models.Conversation.ConversationModel conversation, TaskModel task) { var employeeResult = _employeeService.GetAvailableEmployee(); TaskFormModel form; if (employeeResult.IsWarning || employeeResult.IsError) { await this.SendMessage(conversation, "No available consultant found, try again later."); form = new TaskFormModel { TaskId = task.Id, Properties = new List <TaskFormProperty> { new TaskFormProperty { Id = "isAvailable", Value = "false" } } }; await _activitiWorker.CompleteTaskSubmittingFormAndGetNextAsync((int)conversation.ProcessInstanceId, form); conversation.CustomerId = null; conversation.ProcessInstanceId = null; conversation.ProcessTask = TalkProcessTask.None; _conversationService.Update(conversation); } else { form = new TaskFormModel { TaskId = task.Id, Properties = new List <TaskFormProperty> { new TaskFormProperty { Id = "isAvailable", Value = "true" } } }; var nextTaskResult = await _activitiWorker.CompleteTaskSubmittingFormAndGetNextAsync((int)conversation.ProcessInstanceId, form); var nextTask = nextTaskResult.Value; conversation.ProcessTask = nextTask.ProcessTask; conversation.Messages = null; _conversationService.Update(conversation); await ChangeTask(conversation, nextTask); } }
public ActionResult Delete(int id) { var model = new TaskFormModel(); try { var task = TaskService.TaskFetch(id); this.MapToModel(task, model, true); } catch (Exception ex) { this.ModelState.AddModelError(string.Empty, ex.Message); } return(this.View(model)); }
public ActionResult Edit(int id, TaskFormModel model) { var task = TaskService.TaskFetch(id); this.MapToObject(model, task); task = TaskService.TaskSave(task); if (task.IsValid) { model.Message = Resources.SaveSuccessfulMessage; } this.MapToModel(task, model, true); return(this.View(model)); }
private void MapToObject(TaskFormModel model, Task task) { Csla.Data.DataMapper.Map( model, task, true, "EstimatedCompletedDate", "CompletedDate", "AssignedDate", "StartDate", "Labels"); if (model.Labels == null) { return; } switch (SettingHelper.LabelMode) { case ConfigurationMode.Simple: task.Labels = model.Labels; break; case ConfigurationMode.Advanced: var labels = model.Labels.Split(' '); foreach (var label in labels.Where(label => !task.TaskLabels.Contains(label))) { task.TaskLabels.Add(label); } var taskLabelsToRemove = (from taskLabel in task.TaskLabels where !labels.Contains(taskLabel.Name) select taskLabel.Name) .ToList(); foreach (var taskLabel in taskLabelsToRemove) { task.TaskLabels.Remove(taskLabel); } break; default: break; } }
private async Task CheckPass(Models.Conversation.ConversationModel conversation, TaskModel task) { var messagesResult = await _facebbokMessageService.GetConversationMessages(conversation.FacebookConversationId); var messages = messagesResult.Value; string message = messages.FirstOrDefault()?.Message; if (message == null) { return; } string[] credentials = message.Split('/'); if (credentials.Length != 2) { return; } string login = credentials[0]; string password = credentials[1]; var customerResult = await _customerService.GetCustomerByCredentials(login, password); TaskFormModel form; if (customerResult.IsError) { form = new TaskFormModel { TaskId = task.Id, Properties = new List <TaskFormProperty> { new TaskFormProperty { Id = "isOk", Value = "false" } } }; } else { form = new TaskFormModel { TaskId = task.Id, Properties = new List <TaskFormProperty> { new TaskFormProperty { Id = "isOk", Value = "true" } } }; conversation.CustomerId = customerResult.Value.Id; } var nextTaskResult = await _activitiWorker.CompleteTaskSubmittingFormAndGetNextAsync((int)conversation.ProcessInstanceId, form); var nextTask = nextTaskResult.Value; conversation.ProcessTask = nextTask.ProcessTask; conversation.Messages = null; _conversationService.Update(conversation); await ChangeTask(conversation, nextTask); }
private void MapToModel(Task task, TaskFormModel model, bool ignoreBrokenRules) { Csla.Data.DataMapper.Map(task, model, true, "Labels"); model.Tab = "Task"; model.Statuses = DataHelper.GetStatusList(); model.Categories = DataHelper.GetCategoryList(); model.Projects = DataHelper.GetProjectList(); model.Sprints = DataHelper.GetSprintList(task.ProjectId); model.Users = DataHelper.GetUserList(); if (!task.IsNew) { model.Hours = HourService.HourFetchInfoList(task) .OrderBy(row => row.Date) .AsQueryable(); model.Invoices = InvoiceService.InvoiceFetchInfoList(task) .OrderByDescending(row => row.Number) .AsQueryable(); model.NoteListModel = new NoteListModel { Source = task, Notes = NoteService.NoteFetchInfoList(task).AsQueryable() }; model.LabelListModel = new LabelListModel { Action = "Task", Labels = task.TaskLabels.Select(row => row.Name) }; model.AttachmentListModel = new AttachmentListModel { Source = task, Attachments = AttachmentService.AttachmentFetchInfoList(task).AsQueryable() }; } switch (SettingHelper.LabelMode) { case ConfigurationMode.Simple: model.Labels = task.Labels; break; case ConfigurationMode.Advanced: model.Labels = task.TaskLabels.ToString(); break; default: break; } model.IsNew = task.IsNew; model.IsValid = task.IsValid; if (ignoreBrokenRules) { return; } foreach (var brokenRule in task.BrokenRulesCollection) { this.ModelState.AddModelError(string.Empty, brokenRule.Description); } }
public async Task <Result <TaskModel> > CompleteTaskSubmittingFormAndGetNextAsync(int processInstanceId, TaskFormModel taskFormModel) { var formSubmitResult = await _taskFormService.SubmitTaskFormDataAsync(taskFormModel); if (formSubmitResult.IsError) { return(Result <TaskModel> .Error(formSubmitResult.Messages)); } return(await this.GetCurrentTaskForInstance(processInstanceId)); }