コード例 #1
0
        public async Task <IActionResult> AddToMyProjects([FromBody] int id)
        {
            var  name = User.FindFirst(x => x.Type == ClaimsIdentity.DefaultNameClaimType).Value;
            User user = await db.Users.FirstOrDefaultAsync(u => u.Email == name);

            Project project = await db.Projects.FirstOrDefaultAsync(u => u.ProjectId == id);

            UserProject userProj = new UserProject {
                User = user, Projects = project
            };
            await db.userProjects.AddAsync(userProj);

            await db.SaveChangesAsync();

            return(Ok());
        }
コード例 #2
0
        public async Task <IActionResult> DeleteFromMyProjects(int id)
        {
            Project project = await db.Projects.FirstOrDefaultAsync(u => u.ProjectId == id);

            if (project != null)
            {
                var  name = User.FindFirst(x => x.Type == ClaimsIdentity.DefaultNameClaimType).Value;
                User user = await db.Users.FirstOrDefaultAsync(u => u.Email == name);

                UserProject userProj = new UserProject {
                    User = user, Projects = project
                };
                db.userProjects.Remove(userProj);
                await db.SaveChangesAsync();

                return(Ok(id));
            }
            return(BadRequest());
        }