public async Task <Community> Create(string name, bool showCurrentUser, string supportEmail)
        {
            var creator = _authService.GetCurrentUser();

            var communityId = _context.Communities.Document().Id;

            var community = new Community
            {
                Id              = communityId,
                Name            = name,
                ShowCurrentUser = showCurrentUser,
                SupportEmail    = supportEmail
            };

            var membership = new CommunityMembership
            {
                Name        = creator.Username,
                Role        = CommunityRole.CommunityAdmin,
                CommunityId = communityId,
                UserId      = creator.Id
            };

            await _context.RunTransactionAsync(transaction =>
            {
                _communityRepository.Add(community, transaction);
                _membershipRepository.Add(membership, transaction);
            });

            return(community);
        }
        public async Task <IActionResult> RemoveMemberships(CommunityMembership membership)
        {
            _context.CommunityMemberships.Remove(membership);
            await _context.SaveChangesAsync();

            return(Redirect(HttpContext.Request.Headers["Referer"]));
        }
        public async Task <IActionResult> RemoveMemberships(int studentId, string communityId)
        {
            CommunityMembership removeMember = new CommunityMembership();

            removeMember.CommunityID = communityId;
            removeMember.StudentID   = studentId;
            _context.CommunityMemberships.Remove(removeMember);

            await _context.SaveChangesAsync();

            return(RedirectToAction("EditMemberships", new { id = studentId }));
        }
        public Task <CommunityMembership> Add(User user, string community)
        {
            var membership = new CommunityMembership
            {
                Name        = user.Username,
                UserId      = user.Id,
                CommunityId = community,
                Role        = CommunityRole.User
            };

            return(_membershipRepository.Add(membership));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> RemoveMembership(int?studentId, string communityId)
        {
            if (studentId == null || communityId == null)
            {
                return(NotFound());
            }

            CommunityMembership communityMembership = await _context.CommunityMemberships.FindAsync(studentId, communityId);

            _context.CommunityMemberships.Remove(communityMembership);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(EditMemberships), new { id = studentId }));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> AddMembership(int?studentId, string communityId)
        {
            if (studentId == null || communityId == null)
            {
                return(NotFound());
            }

            Student student = await _context.Students.FindAsync(studentId);

            CommunityMembership newMembership = new CommunityMembership {
                StudentID = (int)studentId, CommunityID = communityId
            };

            _context.Add(newMembership);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(EditMemberships), new { id = studentId }));
        }
Ejemplo n.º 7
0
        public static void Initialize(SchoolCommunityContext context)
        {
            context.Database.EnsureCreated();

            if (context.Students.Any())
            {
                return;
            }

            var students = new Student[]
            {
                new Student {
                    FirstName = "Carson", LastName = "Alexander", EnrollmentDate = DateTime.Parse("2005-09-01")
                },
                new Student {
                    FirstName = "Meredith", LastName = "Alonso", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstName = "Arturo", LastName = "Anand", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    FirstName = "Gytis", LastName = "Barzdukas", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
            };

            foreach (Student s in students)
            {
                context.Students.Add(s);
            }

            context.SaveChanges();

            var communities = new Community[]
            {
                new Community {
                    ID = "A1", Title = "Alpha", Budget = 300
                },
                new Community {
                    ID = "B1", Title = "Beta", Budget = 130
                },
                new Community {
                    ID = "O1", Title = "Omega", Budget = 390
                },
            };

            foreach (Community c in communities)
            {
                context.Communities.Add(c);
            }
            context.SaveChanges();

            var memberships = new CommunityMembership[]
            {
                new CommunityMembership {
                    StudentID = 1, CommunityID = "A1"
                },
                new CommunityMembership {
                    StudentID = 1, CommunityID = "B1"
                },
                new CommunityMembership {
                    StudentID = 1, CommunityID = "O1"
                },
                new CommunityMembership {
                    StudentID = 2, CommunityID = "A1"
                },
                new CommunityMembership {
                    StudentID = 2, CommunityID = "B1"
                },
                new CommunityMembership {
                    StudentID = 3, CommunityID = "A1"
                },
            };

            foreach (var m in memberships)
            {
                context.CommunityMemberships.Add(m);
            }
            context.SaveChanges();
        }
 public Task Delete(CommunityMembership membership) => _membershipRepository.Delete(membership);
 public Task PromoteToCommunityAdmin(CommunityMembership membership)
 {
     membership.Role = CommunityRole.CommunityAdmin;
     return(_membershipRepository.Update(membership));
 }