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()); } }
public void Create(DalFile entity) { var ormFile = entity?.ToOrmFile(); if (ormFile == null) { return; } Context.Set <File>()?.Add(ormFile); }
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 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()); }
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; }