public async Task <IActionResult> Borrow(int id) { var book = _context .Books .Where(b => b.BookId == id) .FirstOrDefault(); var currentUser = GetCurrentUser(); Lend lend = new Lend() { User = currentUser, Book = book, LendDate = DateTime.Now }; book.Lend = lend; currentUser.Lends.Add(lend); _context.Lends.Add(lend); _context.Books.Update(book); _context.Users.Update(currentUser); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public bool LendBooks(Cart cart) { try { var user = _userRepository.GetUserByEmail(HttpContext.Current.User.Identity.Name); foreach (var item in cart.books) { if (item.Available == true) { var lend = new Lend { IdBook = item.Id, IdUser = user.Id, Book = item, User = user, DateBorrowed = DateTime.Now, State = "Wypożyczona", DateReturn = DateTime.Now.AddDays(14) }; _lendRepository.AddLend(lend); } } return(true); } catch { return(false); } }
public async Task <IActionResult> Edit(Guid id, [Bind("IsReturned,RequestedOn,ReturnedOn,MemberId,BookId,Id")] Lend lend) { if (id != lend.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(lend); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LendExists(lend.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BookId"] = new SelectList(_context.Books, "Id", "Id", lend.BookId); ViewData["MemberId"] = new SelectList(_context.Members, "Id", "Id", lend.MemberId); return(View(lend)); }
public ActionResult LendBooks() { var userModel = userManager.FindById(User.Identity.GetUserId()); Cart cart = Session["Cart"] as Cart; if (cart == null || Session["Cart"] == null) { cart = new Cart(); Session["Cart"] = cart; } else { foreach (Book b in cart.Books) { Book book = db.Books.Where(a => a.Id == b.Id).First(); book.Available = false; Lend LendBook = new Lend(); LendBook.DateBorrowed = DateTime.Now; LendBook.DateReturn = DateTime.Now.AddDays(7); LendBook.User = userModel; LendBook.Book = book; LendBook.State = "Borrowed"; book.Borrows.Add(LendBook); } TempData["Success"] = "Added Successfully!"; db.SaveChanges(); } return(RedirectToAction("ShowCart")); }
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name == "colBtn_drop") { Lend model = new Lend(); model.id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["id"].Value); if (LendHelper.Drop(model, new List <string>() { "id" })) { ShowDataGird(); MessageBox.Show("删除成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (dataGridView1.Columns[e.ColumnIndex].Name == "colBtn_alter") { Lend model = new Lend(); model.id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value); model.name = dataGridView1.Rows[e.RowIndex].Cells["name"].Value.ToString(); model.bookname = dataGridView1.Rows[e.RowIndex].Cells["bookname"].Value.ToString(); model.date = dataGridView1.Rows[e.RowIndex].Cells["date"].Value.ToString(); if (LendHelper.AlterByPK(model, "id")) { ShowDataGird(); MessageBox.Show("修改成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public async Task <IActionResult> LendGive([FromForm] ArticleLendGiveViewModel articleLendGive) { var article = _dbContext.Articles.Include(s => s.Lends).FirstOrDefault(a => a.Id == articleLendGive.Id); if (article == null || articleLendGive.LaboratoryId == null || !ModelState.IsValid) { return(RedirectToAction("LendGiveTable")); } var articleUses = _dbContext.ArticleUses.Count(use => use.ArticleId == articleLendGive.Id) + article.Lends.Sum(lend => lend.UnitsUsed); var articlesLeft = article.NumberOfUnits - articleUses; if (articlesLeft < 0) { return(RedirectToAction("LendGiveTable")); } var user = await _userManager.FindByNameAsync(User.Identity.Name); Lend dbarticleLendGive = new Lend(); dbarticleLendGive.Article = article; dbarticleLendGive.LaboratoryId = (int)articleLendGive.LaboratoryId; dbarticleLendGive.LendGiveTime = DateTime.Now; dbarticleLendGive.LendGiveUser = user; _dbContext.Lends.Add(dbarticleLendGive); _dbContext.SaveChanges(); return(RedirectToAction("LendGiveTable")); }
public ActionResult Save(Lend lend) { if (!ModelState.IsValid) { var lendFormViewModel = new LendFormViewModel { Borrower = new Borrower(), Books = _db.Books.ToList() }; return(View("LendForm", lendFormViewModel)); } if (lend.Id == 0) { lend.DateLent = DateTime.Today; _db.Lends.Add(lend); } else //lend.Id != 0 { var lendInDb = _db.Lends.Include(l => l.LendDetails).Single(l => l.Id == lend.Id); lendInDb.BorrowerId = lend.BorrowerId; lendInDb.LendDetails = lend.LendDetails; } _db.SaveChanges(); return(RedirectToAction("Index", "Lends")); }
public async Task <IActionResult> Edit(int id, [Bind("LendId")] Lend lend) { if (id != lend.LendId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(lend); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LendExists(lend.LendId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(lend)); }
/// <summary> /// 借书 /// </summary> /// <param name="copyId">副本ID</param> /// <param name="userId">用户ID</param> public void LendBook(string copyId, string userId) { using (var t = dbcontext.Database.BeginTransaction()) { Lend newLend = new Lend() { user_id = userId, copy_id = copyId, lend_time = DateTime.Now, expire_time = DateTime.Now + new TimeSpan(14, 0, 0, 0), return_time = null }; dbcontext.Lends.Add(newLend); dbcontext.Copies.Find(copyId).status = true; try { dbcontext.SaveChanges(); t.Commit(); } catch (Exception ex) { t.Rollback(); } } }
public void DeleteLend(int lendId) { Lend lend = context.Lend.Find(lendId); context.Lend.Remove(lend); Save(); }
public void UnPostLedger(Lend lend) { organization.LedgersDal.RemoveTransaction(lend.Id); lend.PostStatus = LedgerPostStatus.ReadyToPost; erpNodeDBContext.SaveChanges(); }
public ActionResult DeleteConfirmed(int id) { Lend lend = db.Lends.Find(id); db.Lends.Remove(lend); db.SaveChanges(); return(RedirectToAction("Index")); }
private object CheckIfRentDay(Lend lend) { if (lend.LendDate.Day < DateTime.Now.Day) { return(new ErrorResult(Messages.LendDayCantbePast)); } return(new SuccessResult()); }
public ActionResult DeleteConfirmed(int id) { Lend lend = db.Borrows.Find(id); lend.Book.Available = true; db.Borrows.Remove(lend); db.SaveChanges(); return(RedirectToAction("Index")); }
private IResult CheckIfTheBookHasBeenDelivered(Lend lend) { var result = _lendDal.GetAll(l => l.LendId == lend.LendId); if (result.Any()) { return(new ErrorResult(Messages.RentalNotComeBack)); } return(new SuccessResult()); }
private object CheckIfitisPastDelivery(Lend lend) { var result = _lendDal.GetAll(l => l.LendId == lend.LendId && (lend.LendDate.Day - l.LendPeriod) == 0); if (result.Any()) { return(new ErrorResult(Messages.BookOnRent)); } return(new SuccessResult()); }
public ActionResult Edit([Bind(Include = "Id,PeriodOfLending")] Lend lend) { if (ModelState.IsValid) { db.Entry(lend).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(lend)); }
public ActionResult Edit([Bind(Include = "ID,LendObjectName,LendObjectDescription,From,To,Employee")] Lend lend) { if (ModelState.IsValid) { dbc.Entry(lend).State = EntityState.Modified; dbc.SaveChanges(); return(RedirectToAction("Index")); } return(View(lend)); }
public ActionResult Create([Bind(Include = "Id,DateBorrowed,DateReturn,State")] Lend lend) { if (ModelState.IsValid) { db.Borrows.Add(lend); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(lend)); }
public async Task <IActionResult> Create([Bind("LendId")] Lend lend) { if (ModelState.IsValid) { _context.Add(lend); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(lend)); }
public ActionResult Create([Bind(Include = "Id,PeriodOfLending")] Lend lend) { if (ModelState.IsValid) { db.Lends.Add(lend); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(lend)); }
public ActionResult Create([Bind(Include = "ID,LendObjectName,LendObjectDescription,From,To,Employee")] Lend lend) { if (ModelState.IsValid) { dbc.LendsList.Add(lend); dbc.SaveChanges(); return(RedirectToAction("Index")); } return(View(lend)); }
public ActionResult Edit([Bind(Include = "LendID,BookID,Title,UserID,Fname")] Lend lend) { if (ModelState.IsValid) { db.Entry(lend).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BookID = new SelectList(db.Books, "BookID", "Title", lend.BookID); ViewBag.UserID = new SelectList(db.Users, "UserID", "Fname", lend.UserID); return(View(lend)); }
public IResult Add(Lend lend) { IResult result = BusinessRules.Run(CheckIfTheBookHasBeenDelivered(lend), CheckIfitisPastDelivery(lend), CheckIfRentDay(lend)); if (result != null) { return(result); } _lendDal.Add(lend); return(new SuccessResult(Messages.LendAdded)); }
/// <summary> /// 删除借阅记录 /// </summary> /// <param name="no">借阅记录编号</param> /// <returns>是否删除成功</returns> public int ReturnBook(int no) { Lend lend = _context.Lends.Find(no); // 删除借阅记录 string bid = lend.Bid; _context.Lends.Remove(lend); // 将书的库存加一 var book = _context.Books.FirstOrDefault(b => b.Id == bid); book.Number++; return(_context.SaveChanges()); }
public ActionResult LendBooks(Cart cart) { string url = this.Request.UrlReferrer.AbsolutePath; CartServic cartService = new CartServic(); var cartViewModel = cartService.GetCartViewModel(); var userEmail = User.Identity.Name; using (var dbContext = new MvclibraryEntities()) { var user = dbContext.User.Where(u => u.Email == userEmail).FirstOrDefault(); var lends = dbContext.Lend.ToList(); var userLends = lends.Where(l => l.UserId == user.Id && (l.State == "Odebrano" || l.State == "Na półce czytelnika")).ToList(); if (userLends.Count + cart.books.Count <= user.BorrowLimit) { foreach (var item in cart.books) { var lend = new Lend { BookId = item.Id, UserId = user.Id, DateBorrowed = DateTime.Now, State = "Na półce czytelnika", DateReturn = DateTime.Now.AddDays(14) }; item.Status = "Wypożyczona"; dbContext.Entry(item).State = EntityState.Modified; dbContext.Lend.Add(lend); } dbContext.SaveChanges(); TempData["Message"] = "Książki czekają na Twój odbiór"; TempData["Status"] = "true"; } else { TempData["Message"] = "Masz już wypożyczone " + userLends.Count + " ksiązki. Twój limit wynosi " + user.BorrowLimit; TempData["Status"] = "false"; } } cart.books.Clear(); cartViewModel.cart = cart; return(Redirect(url)); }
public bool AddLend(Lend l) { try { _dbcontext.Entry(l).State = EntityState.Added; _dbcontext.SaveChanges(); return(true); } catch { return(false); } }
private void button1_Click(object sender, EventArgs e) { try { Lend lend = new Lend(); lend.bookID = (int)comboBox1.SelectedValue; lend.visitorID = (int)comboBox2.SelectedValue; lend.lendDate = DateTime.Now.Date; lend.tenancy = (short)(booksTableAdapter.FillPageNumberByID(lend.bookID) / 5); lend.state = false; lend.penaltyFee = 0; if (lendsTableAdapter.IsExist(lend.bookID, lend.visitorID) == 0) { if ((int)lendsTableAdapter.CountNotReturnedLendsByVisitorID(lend.visitorID) < 3) { if (stocksTableAdapter.GetStockByBookID(lend.bookID) != 0) { lendsTableAdapter.Create(lend.bookID, lend.visitorID, lend.lendDate, lend.tenancy, lend.state, lend.penaltyFee); stocksTableAdapter.DecreaseNumber(lend.bookID); Lends.isChanged = true; } else { MessageBox.Show("This book is out of stocks", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); Lends.isChanged = false; } } else { MessageBox.Show("A visitor can currently lend at most 3 books!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); Lends.isChanged = false; } } else { MessageBox.Show("This visitor has already lent the book and not returned back yet!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); Lends.isChanged = false; } } catch (DBConcurrencyException) { MessageBox.Show("An error occured while crud operation on database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Lends.isChanged = false; } finally { this.Dispose(); } }
// GET: Lend/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Lend lend = db.Lends.Find(id); if (lend == null) { return(HttpNotFound()); } return(View(lend)); }
public async Task <IActionResult> Create([Bind("IsReturned,RequestedOn,ReturnedOn,MemberId,BookId,Id")] Lend lend) { if (ModelState.IsValid) { lend.Id = Guid.NewGuid(); _context.Add(lend); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BookId"] = new SelectList(_context.Books, "Id", "Id", lend.BookId); ViewData["MemberId"] = new SelectList(_context.Members, "Id", "Id", lend.MemberId); return(View(lend)); }