private async Task <List <CommonLibrary.DatabaseModels.Task> > GenerateTrack(ChoiceCategory choice, HttpClient client, CreateTask createTask, CommonLibrary.Clients.Model.User user) { var res = await client.PostAsJsonAsync($"{consulWrapper["track-api"]["Scenerios"]}/sql", choice); var open = await res.Content.ReadAsAsync <Scenerio>(); if (open == null) { res = await client.PostAsJsonAsync($"{consulWrapper["track-api"]["Scenerios"]}/sql", new ChoiceCategory { CategoryType = 1058, ViewCategory = 565, Category = 801 }); open = await res.Content.ReadAsAsync <Scenerio>(); } var tasks = new List <CommonLibrary.DatabaseModels.Task>(); foreach (var track in open.ScenerioTasks.Select(x => x.Track)) { var task = new CommonLibrary.DatabaseModels.Task { Name = createTask.Name, Category = open.CategoryID, Creator = user.ID, Description = createTask.Data, Scenario = open.ID, Type = open.TypeID, Email = user.Email, ChangeLogs = new List <ChangeLog>() }; var actionFirst = track.ActionInTracks.OrderBy(x => x.ID).First(); task.ChangeLogs.Add(new ChangeLog { Creator = user.ID, Action = actionFirst.Action.ID, Task = task, DateTime = DateTime.Now }); tasks.Add(task); context.Add(task); context.SaveChanges(); await SendEmail(task, actionFirst.Action, AdressType.New); } return(tasks); }
public async Task <int> Save([FromBody] CommonLibrary.DatabaseModels.Task task) { if (!this.IsAuth()) { return(0); } var taskDatabase = await context.Tasks.FirstOrDefaultAsync(x => x.ID == task.ID); taskDatabase.Description = task.Description; taskDatabase.Name = task.Name; taskDatabase.Rate = task.Rate; taskDatabase.Worker = task.Worker; context.Update(taskDatabase); context.SaveChanges(); return(taskDatabase?.ID ?? -1); }