Exemplo n.º 1
0
 public DalFile FindById(Guid id)
 {
     using (var context = new FileStorageDbContext())
     {
         return context.Files.FirstOrDefault(f => f.Id == id).ToDalFile();
     }
 }
Exemplo n.º 2
0
 public IEnumerable<DalRole> FindAll()
 {
     using (var context = new FileStorageDbContext())
     {
         return context.Roles.AsEnumerable().Select(elem => elem.ToDalRole()).ToList(); ;
     }
 }
Exemplo n.º 3
0
 public void Save(DalUser user)
 {
     using (var context = new FileStorageDbContext())
     {
         context.Users.Add(user.ToOrmUser());
         context.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public IEnumerable<DalUser> FindAll()
 {
     IEnumerable<DalUser> users;
     using (var context = new FileStorageDbContext())
     {
         users = context.Users.AsEnumerable().Select(elem => elem.ToDalUser()).ToList();
     }
     return users;
 }
Exemplo n.º 5
0
 public IEnumerable<DalFile> FindByOwnerId(Guid ownerId)
 {
     using (var context = new FileStorageDbContext())
     {
         return context.Files.AsEnumerable()
             .Where(elem => elem.ToDalFile().OwnerId == ownerId)
             .Select(elem => elem.ToDalFile()).ToList();
     }
 }
Exemplo n.º 6
0
 public void Delete(Guid id)
 {
     using (var context = new FileStorageDbContext())
     {
         var user = context.Users.FirstOrDefault(u => u.Id == id);
         if (user == null) return;
         context.Users.Remove(user);
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
        public IEnumerable<DalFile> FindByNameAndOwnerId(string fileName, Guid ownerId)
        {
            using (var context = new FileStorageDbContext())
            {
                return context.Files.AsEnumerable()
                              .Where(item => item.Name.Contains(fileName) && item.OwnerId == ownerId)
                              .Select(item => item.ToDalFile()).ToList();

            }
        }
Exemplo n.º 8
0
 public void Delete(Guid id)
 {
     using (var context = new FileStorageDbContext())
     {
         var file = context.Files.FirstOrDefault(f => f.Id == id);
         if (file == null) return;
         context.Files.Remove(file);
         context.SaveChanges();
     }
 }
Exemplo n.º 9
0
 public void Save(IEnumerable<DalRole> roles)
 {
     using (var context = new FileStorageDbContext())
     {
         foreach (var dalRole in roles)
         {
             context.Roles.Add(new OrmRole() {Id = dalRole.Id, Name = dalRole.Name});
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 10
0
 public IEnumerable<DalUser> FindByRole(string roleName)
 {
     IEnumerable<DalUser> users;
     using (var context = new FileStorageDbContext())
     {
         users = context.Users.AsEnumerable()
             .Where(elem => elem.Role.Name.Equals(roleName))
             .Select(elem => elem.ToDalUser()).ToList();
     }
     return users;
 }
Exemplo n.º 11
0
 public void DeleteByOwnerId(Guid ownerId)
 {
     using (var context = new FileStorageDbContext())
     {
         var files = context.Files
             .Where(elem => elem.OwnerId == ownerId)
             .Select(elem => elem);
         foreach (var file in files.Where(file => file != null))
         {
             context.Files.Remove(file);
             context.SaveChanges();
         }
     }
 }
Exemplo n.º 12
0
 public IEnumerable<DalFile> FindPublic()
 {
     using (var context = new FileStorageDbContext())
     {
         return context.Files.AsEnumerable()
             .Where(elem => elem.ToDalFile().IsPublic)
             .Select(elem => elem.ToDalFile()).ToList();
     }
 }
Exemplo n.º 13
0
 public void Save(DalFile file)
 {
     using (var context = new FileStorageDbContext())
     {
         var oldFile = context.Files.Where(f => f.Name.Equals(file.Name) && f.Path.Equals(file.Path)).Select(f => f);
         file.Id = oldFile.Count() != 0 ? oldFile.First().Id : Guid.NewGuid();
         context.Files.RemoveRange(oldFile);
         context.Files.Add(file.ToOrmFile());
         context.SaveChanges();
     }
 }
Exemplo n.º 14
0
        public IEnumerable<DalFile> FindPublicByName(string fileName)
        {
            using (var context = new FileStorageDbContext())
            {
                return context.Files.AsEnumerable()
                              .Where(elem => elem.ToDalFile().IsPublic && elem.Name.Contains(fileName))
                              .Select(elem => elem.ToDalFile()).ToList();

            }
        }