public void AddBooks(DalList list, IEnumerable <DalBook> books) { foreach (var book in books) { AddBook(list, book); } }
public int Create(DalList entity) { var obj = entity.ToOrmList(); context.Lists.Add(obj); context.SaveChanges(); return(obj.ListID); }
public static Lists ToOrmList(this DalList list) { return(new Lists { ListID = list.ID, Name = list.Name }); }
public static ServiceList ToServiceList(this DalList list) { return(new ServiceList { ID = list.ID, Name = list.Name }); }
public void Delete(DalList entity) { var t = context.Lists.FirstOrDefault(e => e.ListID == entity.ID); if (t != null) { context.Lists.Remove(t); } }
public void Update(DalList entity) { var g = context.Lists.FirstOrDefault(e => e.ListID == entity.ID); if (g != null) { g.Name = entity.Name; } }
public void DeleteBook(DalList list, DalBook book) { var dbList = context.Lists.FirstOrDefault(e => e.ListID == list.ID); var dbBook = context.Books.FirstOrDefault(e => e.BookID == book.ID); if (dbList != null && dbBook != null) { dbList.Books.Remove(dbBook); context.SaveChanges(); } }
internal static OrmList ToOrmList(DalList list) { if (list != null) { return new OrmList { Id = list.Id, Description = list.Description, OwnerId = list.OwnerId, Title = list.Title } } ; return(null); }
public void ListRepository_Add_IsNotNullWhenGet() { var dbData = new DalList { Id = 100, Description = "aaa", Title = "aaa" }; var dbSetMock = new Mock <DbSet <OrmList> >(); var dbContextMock = new Mock <EntityModelContext>(); dbContextMock.Setup(x => x.Set <OrmList>()).Returns(dbSetMock.Object); var repo = new ListRepository(dbContextMock.Object); repo.Add(dbData); Assert.IsNotNull(repo.Get(100)); }
public IEnumerable <DalBook> GetBooks(DalList list) { return(context.Lists.FirstOrDefault(e => e.ListID == list.ID)?.Books.Select(e => e.ToDalBook())); }
public void Add(DalList entity) => DbSet.Add(Mapper.ToOrmList(entity));
public void Update(DalList entity) => DbSet.AddOrUpdate(Mapper.ToOrmList(entity));