Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
        public void AcceptUser(int projectId, string username)
        {
            using (ctx)
            {
                var project = ctx.Projects.Include(p => p.ReceivedRequests)
                              .FirstOrDefault(p => p.Id == projectId);
                var user = ctx.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 = ctx.Entry(receivedRequest);
                    receivedRequestForDelete.State = EntityState.Deleted;

                    var requestedProject = user.RequestedProjects.
                                           FirstOrDefault(u => u.ProjectId == projectId);

                    var requestedProjectForDelete = ctx.Entry(requestedProject);
                    requestedProjectForDelete.State = EntityState.Deleted;

                    user.AcceptedProjects.Add(
                        new AcceptedProjectRequest
                    {
                        AccountId = requestedProject.AccountId,
                        ProjectId = requestedProject.ProjectId
                    });

                    ctx.SaveChanges();
                }
            }
        }