public override string CreateSort(string projectId, Project clonedProject) { using (var dbContext = new ProjectContext()) { var sortSession = new SortSession() { Project = clonedProject, ProjectId = clonedProject.Id, Reference = projectId }; dbContext.SortSessions.Add(sortSession); dbContext.SaveChanges(); return(sortSession.Id); } }
public override bool SaveSort(SortSession session) { using (var dbContext = new ProjectContext()) { // For some reason, the default group still seems to contain all the cards. // Make sure to remove all the cards from the default or unsorted group. session.Project.Groups.First(x => x.IsUnsorted == true).Cards.Clear(); // Save the cloned project. var existingProject = dbContext.Projects.FirstOrDefault(x => x.Id == session.Project.Id); if (existingProject == null) { dbContext.Add(session.Project); dbContext.SaveChanges(); } else { dbContext.Remove(existingProject); dbContext.SaveChanges(); dbContext.Add(session.Project); dbContext.SaveChanges(); } // Save the sort session. var existingSession = dbContext.SortSessions.FirstOrDefault(x => x.Id == session.Id); if (existingSession == null) { dbContext.Add(session); dbContext.SaveChanges(); } else { dbContext.Remove(existingSession); dbContext.SaveChanges(); dbContext.Add(session); dbContext.SaveChanges(); } } return(true); }
public bool Upload([FromBody] SortSession sortSession) { return(projectManager.SaveSort(sortSession)); }