Beispiel #1
0
        public void Update(Group group)
        {
            using (var _context = new EduhubContext(_connectionString))
            {
                var currentGroupDto = _context.Groups
                                      .Include(g => g.Members)
                                      .Include(g => g.Messages)
                                      .Include(g => g.Invitations)
                                      .Include(g => g.Kicked)
                                      .Include(g => g.Tags)
                                      .Include(g => g.GroupMessages)
                                      .FirstOrDefault(g => g.Id == group.GroupInfo.Id && !g.IsDeleted);

                Ensure.Any.IsNotNull(currentGroupDto, nameof(currentGroupDto),
                                     opt => opt.WithException(new GroupNotFoundException()));

                _context.RemoveRange(currentGroupDto.Tags);
                currentGroupDto.Tags.RemoveAll(t => true);
                _context.RemoveRange(currentGroupDto.Kicked);
                currentGroupDto.Kicked.RemoveAll(t => true);
                _context.RemoveRange(currentGroupDto.Members);
                currentGroupDto.Members.RemoveAll(t => true);

                currentGroupDto.ParseFromGroup(group);

                _context.SaveChanges();
            }
        }
Beispiel #2
0
        public void Update(User user)
        {
            using (var _context = new EduhubContext(_connectionString))
            {
                var userDto = _context.Users
                              .Include(u => u.Contacts)
                              .Include(u => u.Invitations)
                              .Include(u => u.Reviews)
                              .Include(u => u.Tags)
                              .Include(u => u.Notifies)
                              .FirstOrDefault(u => u.Id == user.Id);

                Ensure.Any.IsNotNull(userDto, nameof(user),
                                     opt => opt.WithException(new UserNotFoundException(user.Id)));

                _context.RemoveRange(userDto.Tags);
                userDto.Tags.RemoveAll(t => true);
                _context.RemoveRange(userDto.Contacts);
                userDto.Contacts.RemoveAll(t => true);
                _context.RemoveRange(userDto.Reviews);
                userDto.Reviews.RemoveAll(t => true);
                _context.RemoveRange(userDto.Notifies);
                userDto.Notifies.RemoveAll(t => true);

                userDto.ParseFromUser(user);
                _context.SaveChanges();
            }
        }