public DalFile FindById(Guid id) { using (var context = new FileStorageDbContext()) { return context.Files.FirstOrDefault(f => f.Id == id).ToDalFile(); } }
public IEnumerable<DalRole> FindAll() { using (var context = new FileStorageDbContext()) { return context.Roles.AsEnumerable().Select(elem => elem.ToDalRole()).ToList(); ; } }
public void Save(DalUser user) { using (var context = new FileStorageDbContext()) { context.Users.Add(user.ToOrmUser()); context.SaveChanges(); } }
public IEnumerable<DalUser> FindAll() { IEnumerable<DalUser> users; using (var context = new FileStorageDbContext()) { users = context.Users.AsEnumerable().Select(elem => elem.ToDalUser()).ToList(); } return users; }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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; }
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(); } } }
public IEnumerable<DalFile> FindPublic() { using (var context = new FileStorageDbContext()) { return context.Files.AsEnumerable() .Where(elem => elem.ToDalFile().IsPublic) .Select(elem => elem.ToDalFile()).ToList(); } }
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(); } }
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(); } }