public bool Create(UserModel user) { try { _context.Users.Add(user); _context.SaveChanges(); return(true); } catch { return(false); } }
public bool Create(CategoryModel category) { try { _context.Categories.Add(category); _context.SaveChanges(); return(true); } catch { return(false); } }
public bool Create(BooksModel book) { try { _context.Books.Add(book); _context.SaveChanges(); return(true); } catch { return(false); } }
public bool Create(RequestDetailsModel bbrd) { try { _context.RequestDetails.Add(bbrd); _context.SaveChanges(); return(true); } catch { return(false); } }
public bool CreateRequest(int userId, List <int> bookIds) { try { var checkMonth = _context.Requests.Count(x => x.RequestUserId == userId && x.RequestDate.Month == DateTime.Now.Month && x.RequestDate.Year == DateTime.Now.Year); if (bookIds.Count() > 5 || checkMonth > 2) { return(false); } else { var request = new RequestModel { RequestUserId = userId, RequestDate = DateTime.Now, RequestStatus = Status.Waiting }; _context.Requests.Add(request); _context.SaveChanges(); foreach (var item in bookIds) { var requestdetail = new RequestDetailsModel { RequestID = request.RequestID, BookID = item }; _context.RequestDetails.Add(requestdetail); } _context.SaveChanges(); return(true); } } catch { return(false); } }
// PUT: odata/TitleLists(5) public IHttpActionResult Put([FromODataUri] int key, Delta <TitleList> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TitleList titleList = db.TitleLists.Find(key); if (titleList == null) { return(NotFound()); } patch.Put(titleList); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TitleListExists(key)) { return(NotFound()); } else { throw; } } return(Updated(titleList)); }
// PUT: odata/Fairies(5) public IHttpActionResult Put([FromODataUri] int key, Delta <Fairy> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Fairy fairy = db.Fairies.Find(key); if (fairy == null) { return(NotFound()); } patch.Put(fairy); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FairyExists(key)) { return(NotFound()); } else { throw; } } return(Updated(fairy)); }
// PUT: odata/BookConditions(5) public IHttpActionResult Put([FromODataUri] int key, Delta <BookCondition> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } BookCondition bookCondition = db.BookConditions.Find(key); if (bookCondition == null) { return(NotFound()); } patch.Put(bookCondition); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookConditionExists(key)) { return(NotFound()); } else { throw; } } return(Updated(bookCondition)); }
// PUT: odata/CheckInRecords(5) public IHttpActionResult Put([FromODataUri] int key, Delta <CheckInRecord> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CheckInRecord checkInRecord = db.CheckInRecords.Find(key); if (checkInRecord == null) { return(NotFound()); } patch.Put(checkInRecord); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CheckInRecordExists(key)) { return(NotFound()); } else { throw; } } return(Updated(checkInRecord)); }
public void Add(Book entity) { _dbContext.Books.Add(entity); _dbContext.SaveChanges(); }
protected void Save() { _context.SaveChanges(); }