예제 #1
0
        public void AddFile(DalBook book, DalFile file)
        {
            var dbBook = context.Books.FirstOrDefault(e => e.BookID == book.ID);

            if (dbBook != null)
            {
                context.Files.Add(file.ToOrmFile());
            }
        }
예제 #2
0
        public void Create(DalFile entity)
        {
            var ormFile = entity?.ToOrmFile();

            if (ormFile == null)
            {
                return;
            }
            Context.Set <File>()?.Add(ormFile);
        }
예제 #3
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();
     }
 }
예제 #4
0
        public DalFile Create(DalFile entity)
        {
            if (ReferenceEquals(entity, null))
            {
                var error = new ArgumentNullException(nameof(entity), "parametr can't be null");
                logger.Error(error, error.Message);
                throw error;
            }
            var file = context.Set <Files>().Add(entity.ToOrmFile());

            return(file.ToDalFile());
        }
예제 #5
0
        public void Update(DalFile entity)
        {
            if (ReferenceEquals(entity, null))
            {
                var error = new ArgumentNullException(nameof(entity), "parametr can't be null");
                logger.Error(error, error.Message);
                throw error;
            }

            var file = context.Set <Files>().Find(entity.ID);
            var e    = entity.ToOrmFile();

            file.Folder   = e.Folder;
            file.dateTime = e.dateTime;
            file.folderId = e.folderId;
            file.name     = e.name;

            file.content   = e.content;
            file.FileTypes = e.FileTypes;

            context.Entry(file).State = EntityState.Modified;
        }