public string Delete([FromBody] BookAndShelve item) { var ExistShelve = contaxt1.Shelves.Where(z => z.Id == item.ShelveId).FirstOrDefault(); if (ExistShelve == null) { return("This shelve is not exis "); } else { var existBook = contaxt1.bookAndShelves.Where(z => z.BookID == item.BookID && z.ShelveId == item.ShelveId); if (existBook == null) { return("This Book is Not Exist In This Shelve "); } else { contaxt1.Remove(existBook); contaxt1.SaveChanges(); return("Remov The Book "); } } }
public async Task <IActionResult> Add([FromBody] BookAndShelve item) { var MyBAndSh = new BookAndShelve { BookID = item.BookID, ShelveId = item.ShelveId }; var res = await contaxt1.bookAndShelves.AnyAsync(c => c.ShelveId == item.ShelveId); if (res) { return(NotFound()); } else { contaxt1.bookAndShelves.Add(MyBAndSh); contaxt1.SaveChanges(); return(Ok()); } }