public bool delete([FromBody] int id) { try { using (var context = new FSEEntities()) { var data = context.Projects.FirstOrDefault(x => x.Id == id); context.Projects.Remove(data); var user = context.Users.FirstOrDefault(x => x.ProjectId == id); if (user != null) { user.ProjectId = null; } context.SaveChanges(); } } catch (Exception) { return(false); } return(true); }
public bool SaveUser(UserDto userdata) { if (userdata != null) { if (userdata.Id == 0) { try { using (var context = new FSEEntities()) { var newUser = new User() { FirstName = userdata.FirstName, LastName = userdata.LastName, EmployeeId = userdata.EmployeeId }; context.Users.Add(newUser); context.SaveChanges(); } } catch (Exception ex) { return(false); } } else { try { using (var context = new FSEEntities()) { var userDetails = context.Users.FirstOrDefault(x => x.Id == userdata.Id); if (userDetails != null) { userDetails.FirstName = userdata.FirstName; userDetails.LastName = userdata.LastName; userDetails.EmployeeId = userdata.EmployeeId; } else { return(false); } context.SaveChanges(); } } catch (Exception ex) { return(false); } } } return(true); }
public bool delete(int id) { try { using (var context = new FSEEntities()) { var data = context.Tasks.FirstOrDefault(x => x.Id == id); data.Status = "Completed"; context.SaveChanges(); } } catch (Exception) { return(false); } return(true); }
public bool deleteUser([FromBody] int id) { try { using (var context = new FSEEntities()) { var user = context.Users.FirstOrDefault(x => x.Id == id); if (user != null) { context.Users.Remove(user); context.SaveChanges(); return(true); } return(false); } } catch (Exception ex) { return(false); } }
public bool SaveTasks(TaskDto data) { if (data != null) { if (data.IsParentTask) { using (var context = new FSEEntities()) { var newParentTask = new ParentTask() { Description = data.Description, }; context.ParentTasks.Add(newParentTask); context.SaveChanges(); } } else { if (data.Id == 0) { try { using (var context = new FSEEntities()) { var newTask = new Task() { Description = data.Description, StartDate = data.StartDate, EndDate = data.EndDate, Priority = data.Priority, ProjectId = data.ProjectId, ParentId = data.ParentId, Status = "New" }; context.Tasks.Add(newTask); var user = context.Users.FirstOrDefault(x => x.Id == data.UserId); user.TaskId = newTask.Id; context.SaveChanges(); } } catch (Exception ex) { return(false); } } else { try { using (var context = new FSEEntities()) { var task = context.Tasks.FirstOrDefault(x => x.Id == data.Id); if (task != null) { task.Description = data.Description; task.StartDate = data.StartDate; task.EndDate = data.EndDate; task.Priority = data.Priority; task.ProjectId = data.ProjectId; task.ParentId = data.ParentId; task.Status = "InProgress"; var user = context.Users.FirstOrDefault(x => x.Id == data.UserId); user.TaskId = task.Id; } else { return(false); } context.SaveChanges(); } } catch (Exception ex) { return(false); } } } } return(true); }
public bool SaveProjects(ProjectDto data) { if (data != null) { if (data.Id == 0) { try { using (var context = new FSEEntities()) { var newProject = new Project() { Name = data.Name, StartDate = data.StartDate, EndDate = data.EndDate, Priority = data.Priority }; context.Projects.Add(newProject); var user = context.Users.FirstOrDefault(x => x.Id == data.SelectedUser.Id); user.ProjectId = newProject.Id; context.SaveChanges(); } } catch (Exception ex) { return(false); } } else { try { using (var context = new FSEEntities()) { var project = context.Projects.FirstOrDefault(x => x.Id == data.Id); if (project != null) { project.Name = data.Name; project.StartDate = data.StartDate; project.EndDate = data.EndDate; project.Priority = data.Priority; } else { return(false); } var user = context.Users.FirstOrDefault(x => x.ProjectId == data.Id); user.ProjectId = null; var newuser = context.Users.FirstOrDefault(x => x.Id == data.SelectedUser.Id); newuser.ProjectId = data.Id; context.SaveChanges(); } } catch (Exception ex) { return(false); } } } return(true); }