Exemplo n.º 1
0
        public async Task <IActionResult> OnPostDeleteProjectAsync(int?id)
        {
            _log.LogWarning($"OnPost: MemberId {id}, DROP project {ProjectIdToDelete}");
            if (id == null)
            {
                return(NotFound());
            }

            Member = await _context.Members.Include(pm => pm.ProjectMembers).ThenInclude(p => p.Project).FirstOrDefaultAsync(m => m.MemberID == id);

            AllProjects = await _context.Projects.ToListAsync();

            ProjectDropDown = new SelectList(AllProjects, "ProjectID", "ProjectName");

            if (Member == null)
            {
                return(NotFound());
            }

            ProjectMember projectToDrop = _context.ProjectMembers.Where(pm => pm.ProjectID == ProjectIdToDelete && pm.MemberID == id).FirstOrDefault();

            if (projectToDrop != null)
            {
                _context.Remove(projectToDrop);
                _context.SaveChanges();
            }
            else
            {
                _log.LogWarning("Member not in project");
            }
            return(RedirectToPage(new { id = id }));
        }
        public async Task <IActionResult> OnPostDeleteMemberAsync(int?id)
        {
            _log.LogWarning($"OnPost: ProjectID {id}, DROP member {MemberIdToDelete}");
            if (id == null)
            {
                return(NotFound());
            }

            Project = await _context.Projects.Include(pm => pm.ProjectMembers).ThenInclude(m => m.Member).FirstOrDefaultAsync(m => m.ProjectID == id);

            if (Project == null)
            {
                return(NotFound());
            }

            ProjectMember memberToDrop = _context.ProjectMembers.Where(pm => pm.MemberID == MemberIdToDelete && pm.ProjectID == id).FirstOrDefault();

            if (memberToDrop != null)
            {
                _context.Remove(memberToDrop);
                _context.SaveChanges();
            }
            else
            {
                _log.LogWarning("Member NOT assigned project");
            }
            return(Page());
        }