public static void Initialize(LibraryDataContext db) { db.Books.AddRange( GetSeedingBooks() ); db.SaveChanges(); }
public static void AddPatron(Patron patron) { using (LibraryDataContext ctx = new LibraryDataContext()) { ctx.Patrons.Add(patron); ctx.SaveChanges(); } }
public static void AddAuthor(Data.Author author) { using (Data.LibraryDataContext ctx = new LibraryDataContext()) { ctx.Authors.Add(author); ctx.SaveChanges(); } }
public static void AddPublisher(Publisher publisher) { using (LibraryDataContext ctx = new LibraryDataContext()) { ctx.Publishers.Add(publisher); ctx.SaveChanges(); } }
public static void Update(Lookup lookup) { using (LibraryDataContext ctx = new LibraryDataContext()) { ctx.Lookups.Attach(lookup); ctx.Entry(lookup).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } }
public static void DeleteAuthor(long id) { using (Data.LibraryDataContext ctx = new LibraryDataContext()) { Author a = ctx.Authors.Find(id); ctx.Authors.Remove(a); ctx.SaveChanges(); } }
public static void UpdatePublisher(Publisher persistentPublisher) { using (LibraryDataContext ctx = new LibraryDataContext()) { ctx.Publishers.Attach(persistentPublisher); ctx.Entry(persistentPublisher).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } }
public static void DeletePatron(long id) { using (LibraryDataContext ctx = new LibraryDataContext()) { Patron toDelete = ctx.Patrons.Find(id); ctx.Patrons.Remove(toDelete); ctx.SaveChanges(); } }
public static void DeletePublisher(long publisherID) { using (LibraryDataContext ctx = new LibraryDataContext()) { Publisher publisher = ctx.Publishers.Find(publisherID); ctx.Publishers.Remove(publisher); ctx.SaveChanges(); } }
public CreateBookResponse CreateBook(CreateBookRequest request) { var response = new CreateBookResponse(); var entity = CommonLogic.SetMapping <CreateBookRequest, Book>(request); try { //----------------------using EF----------------- _context.Add(entity); _context.SaveChanges(); response.IsSuccess = true; } catch { throw new Exception(); } return(response); }
public static void UpdateAuthor(Author author) { using (Data.LibraryDataContext ctx = new LibraryDataContext()) { ctx.Authors.Attach(author); ctx.Entry(author).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } }
public static void UpdatePatron(Patron patron) { using (LibraryDataContext ctx = new LibraryDataContext()) { ctx.Patrons.Attach(patron); ctx.Entry(patron).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } }
public static void Delete(Lookup lookup) { using (LibraryDataContext ctx = new LibraryDataContext()) { ctx.Lookups.Attach(lookup); ctx.Entry(lookup).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); } }
public async Task <IActionResult> AddMember([FromBody] AddMemberModel model) { if (model == null) { return(BadRequest()); } await appDbContext.Members.AddAsync(new Member { MemberId = model.MemberId, JoiningDate = model.JoiningDate, FirstName = model.FirstName, LastName = model.LastName }); await appDbContext.ContactDetails.AddAsync(new ContactDetail { MemberId = model.MemberId, EmailAddress = model.EmailAddress, MobileNo = model.MobileNo }); await appDbContext.Addresses.AddAsync(new Address { MemberId = model.MemberId, AddressLine = model.AddressLine, CityName = model.CityName, StateName = model.StateName }); appDbContext.SaveChanges(); return(new OkObjectResult("{}")); }
public async Task <IActionResult> AddBook([FromBody] AddBookModel book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } foreach (var author in book.Authors) { if (!appDbContext.Authors.Any(x => x.Author == author.Author)) { await appDbContext.Authors.AddAsync(new Authors { Author = author.Author }); } } if (book.CategoryName != null) { await appDbContext.BookCategories.AddAsync(new BookCategory { CategoryName = book.CategoryName }); } appDbContext.SaveChanges(); await appDbContext.Books.AddAsync( new Book { Title = book.Title, ISBN = book.ISBN, CategoryId = book.CategoryId, Pages = book.Pages, Quantity = book.Quantity, Ratings = book.Ratings, YearOfPublish = book.YearOfPublish }); for (int i = 1; i <= book.Quantity; i++) { await appDbContext.BookMetadatas.AddAsync(new BookMetadata { ISBN = book.ISBN, Status = true }); } foreach (var author in book.Authors) { await appDbContext.BookAuthors.AddAsync(new BookAuthor { ISBN = book.ISBN, AuthorId = author.AuthorId }); } await appDbContext.SaveChangesAsync(); return(new OkObjectResult("{}")); }
public static void Add(Lookup lookup) { using (LibraryDataContext ctx = new LibraryDataContext()) { using (DbContextTransaction transaction = ctx.Database.BeginTransaction()) { int nextID = ctx.Lookups.Where(l => l.LookupName == lookup.LookupName).Max(l => l.ID) + 1; lookup.ID = nextID; ctx.Lookups.Add(lookup); ctx.SaveChanges(); } } }