Ejemplo n.º 1
0
 public IList <Hotel> GetAll()
 {
     using (var context = new FileStreamContext())
     {
         return(context.Hotels.ToList());
     }
 }
Ejemplo n.º 2
0
 public IList <Room> GetAll()
 {
     using (var context = new FileStreamContext())
     {
         return(context.Rooms.ToList());
     }
 }
Ejemplo n.º 3
0
 public IList <Photo> GetAll()
 {
     using (var context = new FileStreamContext())
     {
         return(context.Photos.ToList());
     }
 }
Ejemplo n.º 4
0
 public IList <Location> GetAll()
 {
     using (var context = new FileStreamContext())
     {
         return(context.Locations.ToList());
     }
 }
Ejemplo n.º 5
0
 public void Insert(Room entity)
 {
     using (var context = new FileStreamContext())
     {
         context.Rooms.Add(entity);
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public void Update(Room entity)
 {
     using (var context = new FileStreamContext())
     {
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 7
0
 public void Insert(Location entity)
 {
     using (var context = new FileStreamContext())
     {
         context.Locations.Add(entity);
         context.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 public void Delete(int id)
 {
     using (var context = new FileStreamContext())
     {
         context.Entry(new Room {
             Id = id
         }).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 public FileStreamContext Open(IValue fileName, IValue openingMode, IValue fileAccess = null, IValue bufferSize = null)
 {
     if (bufferSize == null)
     {
         return(FileStreamContext.Constructor(fileName, openingMode, fileAccess));
     }
     else
     {
         return(FileStreamContext.Constructor(fileName, openingMode, fileAccess, bufferSize));
     }
 }
Ejemplo n.º 10
0
 public Room GetById(int id)
 {
     using (var context = new FileStreamContext())
     {
         var room = context.Rooms.FirstOrDefault(r => r.Id == id);
         if (room != null)
         {
             context.Entry(room)
             .Collection(r => r.Photos)
             .Load();
         }
         return(room);
     }
 }
Ejemplo n.º 11
0
 public Location GetById(int id)
 {
     using (var context = new FileStreamContext())
     {
         var location = context.Locations.FirstOrDefault(l => l.Id == id);
         if (location != null)
         {
             context.Entry(location)
             .Collection(l => l.Hotels)
             .Load();
         }
         return(location);
     }
 }
Ejemplo n.º 12
0
        public void Insert(Photo entity)
        {
            using (var context = new FileStreamContext())
            {
                using (var tx = new TransactionScope())
                {
                    context.Photos.Add(entity);
                    context.SaveChanges();

                    SavePhotoData(context, entity);

                    tx.Complete();
                }
            }
        }
Ejemplo n.º 13
0
        public void Update(Photo entity)
        {
            using (var context = new FileStreamContext())
            {
                using (var tx = new TransactionScope())
                {
                    context.Entry(entity).State = EntityState.Modified;
                    context.SaveChanges();

                    SavePhotoData(context, entity);

                    tx.Complete();
                }
            }
        }
Ejemplo n.º 14
0
        public Hotel GetById(int id)
        {
            using (var context = new FileStreamContext())
            {
                var hotel = context.Hotels.FirstOrDefault(h => h.Id == id);
                if (hotel != null)
                {
                    context.Entry(hotel)
                    .Reference(h => h.Location)
                    .Load();

                    context.Entry(hotel)
                    .Collection(h => h.Rooms)
                    .Load();
                }
                return(hotel);
            }
        }
Ejemplo n.º 15
0
        private void SavePhotoData(FileStreamContext context, Photo entity)
        {
            var selectStatement = String.Format(RowDataStatement, context.GetTableName <Photo>());

            var rowData =
                context.Database.SqlQuery <FileStreamRowData>(selectStatement, new SqlParameter("id", entity.Id))
                .First();

            using (var destination = new SqlFileStream(rowData.Path, rowData.Transaction, FileAccess.Write))
            {
                var buffer = new byte[16 * 1024];
                using (var ms = new MemoryStream(entity.Data))
                {
                    int bytesRead;
                    while ((bytesRead = ms.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        destination.Write(buffer, 0, bytesRead);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public Photo GetById(int id)
        {
            using (var context = new FileStreamContext())
            {
                var photo = context.Photos.FirstOrDefault(p => p.Id == id);
                if (photo == null)
                {
                    return(null);
                }

                using (var tx = new TransactionScope())
                {
                    var selectStatement = String.Format(RowDataStatement, context.GetTableName <Photo>());

                    var rowData =
                        context.Database.SqlQuery <FileStreamRowData>(selectStatement, new SqlParameter("id", id))
                        .First();

                    using (var source = new SqlFileStream(rowData.Path, rowData.Transaction, FileAccess.Read))
                    {
                        var buffer = new byte[16 * 1024];
                        using (var ms = new MemoryStream())
                        {
                            int bytesRead;
                            while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                ms.Write(buffer, 0, bytesRead);
                            }
                            photo.Data = ms.ToArray();
                        }
                    }

                    tx.Complete();
                }

                return(photo);
            }
        }