public void SendRequestToProject(string username, int projectId) { using (ctx) { var user = ctx.Users.Include(x => x.RequestedProjects).FirstOrDefault(x => x.UserName == username); var project = ctx.Projects.Include(x => x.ReceivedRequests).FirstOrDefault(x => x.Id == projectId); if (user != null && project != null) { var userRequest = new RequestedProjectRequest() { AccountId = user.Id, ProjectId = projectId }; var projectRequest = new ReceivedProjectRequest() { ProjectId = projectId, AccountId = user.Id }; user.RequestedProjects.Add(userRequest); project.ReceivedRequests.Add(projectRequest); ctx.SaveChanges(); } } }
public void Create(CreateProjectDTO projectDto) { using (ctx) { var userId = ctx.Users.FirstOrDefault(u => u.Email == projectDto.UserEmail).Id; var project = GenerateModel(userId, projectDto); ctx.Projects.Add(project); ctx.SaveChanges(); } }
public void AcceptUser(int projectId, string username) { var project = new Project(); var user = new ApplicationUser(); using (EducationSystemDbContext db = new EducationSystemDbContext()) { project = db.Projects.Include(p => p.ReceivedRequests) .FirstOrDefault(p => p.Id == projectId); user = db.Users.Include(u => u.RequestedProjects) .FirstOrDefault(u => u.UserName == username); if (project != null) { var receivedRequest = project.ReceivedRequests.Where(u => u.Account != null). FirstOrDefault(u => u.Account.UserName == username); var receivedRequestForDelete = db.Entry(receivedRequest); receivedRequestForDelete.State = EntityState.Deleted; var requestedProject = user.RequestedProjects. FirstOrDefault(u => u.ProjectId == projectId); var requestedProjectForDelete = db.Entry(requestedProject); requestedProjectForDelete.State = EntityState.Deleted; user.AcceptedProjects.Add(new AcceptedProjectRequest { AccountId = requestedProject.AccountId, ProjectId = requestedProject.ProjectId }); db.SaveChanges(); } } }
public void AcceptProject(int projectId, string username) { using (EducationSystemDbContext db = new EducationSystemDbContext()) { var user = db.Users.Include(x => x.ReceivedProjectRequests).FirstOrDefault(x => x.UserName == username); var project = db.Projects.Include(x => x.RequestedDevelopers).FirstOrDefault(x => x.Id == projectId); if (user != null && project != null) { var userRequest = user.ReceivedProjectRequests .FirstOrDefault(x => x.ProjectId == projectId && x.Account.UserName == username); var projectRequest = project.RequestedDevelopers .FirstOrDefault(x => x.ProjectId == projectId && x.Account.UserName == username); user.ReceivedProjectRequests.Remove(userRequest); project.RequestedDevelopers.Remove(projectRequest); user.AcceptedProjects.Add(new AcceptedProjectRequest() { AccountId = userRequest.AccountId, ProjectId = userRequest.ProjectId }); project.AcceptedDevelopers.Add(new AcceptedProjectRequest() { AccountId = projectRequest.AccountId, ProjectId = projectRequest.ProjectId }); db.SaveChanges(); } } }
public void Create(CreateProjectDTO projectDto) { using (EducationSystemDbContext db = new EducationSystemDbContext()) { var userId = db.Users.FirstOrDefault(u => u.Email == projectDto.UserEmail).Id; var project = GenerateModel(userId, projectDto); db.Projects.Add(project); db.SaveChanges(); } }
public void AddSkill(SkillDto skillDto) { using (EducationSystemDbContext db = new EducationSystemDbContext()) { var user = db.Users.Include(x => x.Skills).FirstOrDefault(x => x.UserName == skillDto.UserName); var skill = new Skill() { Type = skillDto.GetSkillType() }; user.Skills.Add(skill); db.SaveChanges(); } }
public void Edit(ProjectFilter filter) { using (EducationSystemDbContext db = new EducationSystemDbContext()) { var project = db.Projects.FirstOrDefault(p => p.Id == filter.Id); project.Name = filter.Name; project.GitHubUrl = filter.GitHubUrl; project.StartDate = filter.StartDate; project.EndDate = filter.EndDate; project.Description = filter.Description; project.Requirements = filter.Requirements; project.IsTeamFormed = filter.StartDate != null ? true : false; project.Resources = filter.Resources; project.SkillsNeeded = filter.SkillsNeeded; db.SaveChanges(); } }