예제 #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();
            }
        }
예제 #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();
            }
        }
 public void Add(string newTag)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         _context.Tags.Add(new TagDto(newTag));
         _context.SaveChanges();
     }
 }
 public void Update(Tag tag)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var tagDto = _context.Tags.FirstOrDefault(t => t.Name == tag.Name);
         tagDto.Popularity = tag.Popularity;
         _context.SaveChanges();
     }
 }
 public void AddFile(UserFile file)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var userFileDto = new UserFileDto(file.Filename, file.ContentType);
         _context.Files.Add(userFileDto);
         _context.SaveChanges();
     }
 }
 public void Update(Sanction sanction)
 {
     using (var context = new EduhubContext(_connectionString))
     {
         var sanctionDto = context.Sanctions.FirstOrDefault(s => s.Id == sanction.Id);
         sanctionDto.ParseFromSanction(sanction);
         context.SaveChanges();
     }
 }
 public void UpdateKey(Key key)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var keyDto = _context.Keys.FirstOrDefault(k => k.Value == key.Value);
         keyDto.UpdateKey(key);
         _context.SaveChanges();
     }
 }
예제 #8
0
 public void Delete(User user)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var userDto = new UserDto();
         userDto.ParseFromUser(user);
         _context.Users.Remove(userDto);
         _context.SaveChanges();
     }
 }
 public void AddKey(Key key)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var keyDto = KeyDtoExtensions.ParseFromKey(key);
         _context.Keys.Add(keyDto);
         _context.SaveChanges();
         key.Value = keyDto.Value;
     }
 }
예제 #10
0
 public void Delete(Group group)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var currentGroupDto = _context.Groups.FirstOrDefault(g => g.Id == group.GroupInfo.Id);
         Ensure.Any.IsNotNull(currentGroupDto, nameof(currentGroupDto),
                              opt => opt.WithException(new GroupNotFoundException()));
         currentGroupDto.IsDeleted = true;
         _context.SaveChanges();
     }
 }
예제 #11
0
 public void Add(Group group)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var groupDto = new GroupDto();
         groupDto.ParseFromGroup(group);
         _context.Groups.Add(groupDto);
         _context.SaveChanges();
         group.GroupInfo.Id = groupDto.Id;
     }
 }
예제 #12
0
 public void Add(User user)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var userDto = new UserDto();
         userDto.ParseFromUser(user);
         _context.Users.Add(userDto);
         _context.SaveChanges();
         user.Id = userDto.Id;
     }
 }
 public void Add(Sanction sanction)
 {
     using (var context = new EduhubContext(_connectionString))
     {
         var sanctionDto = new SanctionDto();
         sanctionDto.ParseFromSanction(sanction);
         context.Sanctions.Add(sanctionDto);
         context.SaveChanges();
         sanction.Id = sanctionDto.Id;
     }
 }
예제 #14
0
 public User GetUserByEmail(string email)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var userDto = _context.Users
                       .Include(u => u.Contacts)
                       .Include(u => u.Invitations)
                       .Include(u => u.Tags)
                       .Include(u => u.Reviews)
                       .Include(u => u.Notifies)
                       .FirstOrDefault(u => u.Email == email);
         Ensure.Any.IsNotNull(userDto, nameof(email),
                              opt => opt.WithException(new UserNotFoundException(email)));
         var user = UserExtensions.ParseFromUserDto(userDto);
         _context.SaveChanges();
         return(user);
     }
 }