public List <UserDto> searchData(string criteria) { var data = new List <UserDto>(); //if(string.IsNullOrWhiteSpace(criteria)) //{ // return Users(0); //} using (var context = new FSEEntities()) { var list = context.Users.Where(x => criteria == "0" || x.FirstName.Contains(criteria) || x.LastName.Contains(criteria)).ToList(); if (list != null && list.Any()) { list.ForEach(x => { data.Add(new UserDto { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, EmployeeId = x.EmployeeId }); }); } } return(data); }
public List <UserDto> Users(int id) { var users = new List <UserDto>(); using (var context = new FSEEntities()) { var userList = context.Users.Where(x => id == 0 || x.Id == id).ToList(); if (userList != null && userList.Any()) { userList.ForEach(x => { users.Add(new UserDto { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, EmployeeId = x.EmployeeId }); }); } } return(users); }
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 List <ProjectDto> searchData(string criteria) { var projects = new List <ProjectDto>(); using (var context = new FSEEntities()) { var list = context.Projects.Where(x => criteria == null || x.Name.Contains(criteria)).ToList(); if (list != null && list.Any()) { var newTasks = new List <TaskDto>(); list.ForEach(x => { var selectedUser = x.Users?.FirstOrDefault() ?? new User(); var tasks = x.Tasks; if (tasks != null & tasks.Any()) { tasks.ToList().ForEach(t => { newTasks.Add(new TaskDto { Id = t.Id, Description = t.Description, StartDate = t.StartDate, EndDate = t.EndDate, Priority = t.Priority, Status = t.Status, ParentId = t.ParentId, ParentTaskName = t.ParentTask?.Description }); }); } projects.Add(new ProjectDto { Id = x.Id, Name = x.Name, StartDate = x.StartDate, EndDate = x.EndDate, Priority = x.Priority, TotalTasks = x.Tasks?.Count() ?? 0, CompletedTasks = x.Tasks?.Count(z => z.Status == "Completed") ?? 0, SelectedUser = new UserDto { Id = selectedUser.Id, FirstName = selectedUser.FirstName, LastName = selectedUser.LastName, EmployeeId = selectedUser.EmployeeId }, Tasks = newTasks }); }); } } return(projects); }
public List <TaskDto> searchData(string criteria) { var tasks = new List <TaskDto>(); using (var context = new FSEEntities()) { var list = context.Tasks.Where(x => criteria == null || x.Description.Contains(criteria)).ToList(); if (list != null && list.Any()) { list.ForEach(x => { var user = x.Users?.FirstOrDefault(); var taskUser = new UserDto(); if (user != null) { taskUser = new UserDto { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, EmployeeId = user.EmployeeId }; } tasks.Add(new TaskDto { Id = x.Id, Description = x.Description, StartDate = x.StartDate, EndDate = x.EndDate, Priority = x.Priority, Status = x.Status, User = taskUser, Project = new ProjectDto { Id = x.Project?.Id ?? 0, Name = x.Project?.Name, }, ParentId = x.ParentId, ParentTaskName = x.ParentTask?.Description }); }); } } return(tasks); }
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 List <ParentTaskDto> GetParentTask(int id) { var tasks = new List <ParentTaskDto>(); using (var context = new FSEEntities()) { var list = context.ParentTasks.Where(x => id == 0 || x.Id == id).ToList(); if (list != null && list.Any()) { list.ForEach(x => { tasks.Add(new ParentTaskDto { Id = x.Id, Description = x.Description }); }); } } return(tasks); }
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); }