Пример #1
0
        public async Task <IActionResult> Edit(long id, [Bind("Id,takeData,StudentId,BookId")] StudentBook studentBook)
        {
            if (id != studentBook.BookId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(studentBook);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentBookExists(studentBook.BookId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]    = new SelectList(_context.Books, "Id", "Id", studentBook.BookId);
            ViewData["StudentId"] = new SelectList(_context.Students, "Id", "Id", studentBook.StudentId);
            return(View(studentBook));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            StudentBook studentBook = db.StudentBooks.Find(id);

            db.StudentBooks.Remove(studentBook);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult BookForFuture([Bind(Include = "CallNumber")] StudentBook studentBook, string datefield)
 {
     studentBook.StudentId    = Convert.ToInt32(Session["id"]);
     studentBook.IssueDate    = Convert.ToDateTime(datefield).Date;
     studentBook.DueDate      = Convert.ToDateTime(datefield).AddDays(15).Date;
     studentBook.IssueStatus  = "Processing";
     studentBook.CheckoutDate = null;
     db.StudentBooks.Add(studentBook);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
 // GET: StudentBooks/Create
 public ActionResult Create(StudentBook studentBook, int sid, int callNumber)
 {
     studentBook.StudentId    = Convert.ToInt32(Session["id"]);
     studentBook.CallNumber   = callNumber;
     studentBook.IssueDate    = DateTime.Now.Date;
     studentBook.DueDate      = DateTime.Now.AddDays(15).Date;
     studentBook.IssueStatus  = "Processing";
     studentBook.CheckoutDate = null;
     db.StudentBooks.Add(studentBook);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
 public ActionResult Edit([Bind(Include = "Id,StudentId,CallNumber,IssueDate,DueDate,IssueStatus,CheckoutDate")] StudentBook studentBook)
 {
     if (ModelState.IsValid)
     {
         db.Entry(studentBook).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("IndexAdmin"));
     }
     ViewBag.CallNumber = new SelectList(db.Books, "CallNumber", "ISBN", studentBook.CallNumber);
     ViewBag.StudentId  = new SelectList(db.Students, "StudentId", "StudentName", studentBook.StudentId);
     return(View(studentBook));
 }
Пример #6
0
        public async Task AddBookToFavorites(AddBookToFavoritesViewModel request)
        {
            Book book = await bookRepository.GetByTitle(request.Booktitle);

            Student user = await studentRepository.GetByName(request.Name, request.Surname);

            StudentBook createRequest = new StudentBook {
                BookId = book.Id, StudentId = user.Id
            };

            await studentBookRepository.Create(createRequest);
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("Id,takeData,StudentId,BookId")] StudentBook studentBook)
        {
            if (ModelState.IsValid)
            {
                _context.Add(studentBook);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]    = new SelectList(_context.Books, "Id", "Id", studentBook.BookId);
            ViewData["StudentId"] = new SelectList(_context.Students, "Id", "Id", studentBook.StudentId);
            return(View(studentBook));
        }
        // GET: StudentBooks/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentBook studentBook = db.StudentBooks.Find(id);

            if (studentBook == null)
            {
                return(HttpNotFound());
            }
            return(View(studentBook));
        }
        public async Task AddBookToStudent(int bookId, int studentId)
        {
            Book book = await GetBookWithSubjects(bookId);

            Student student = await _context.Students.FindAsync(studentId);

            StudentBook studentBook = new StudentBook
            {
                Student = student,
                Book    = book
            };

            await _context.StudentBooks.AddAsync(studentBook);

            await _context.SaveChangesAsync();
        }
Пример #10
0
        private JsonResult <Result> StudentBorrowBook(StudentBook studentBook)
        {
            var oldstudentbook = db.StudentBooks
                                 .Where(x => x.StudentId == studentBook.StudentId &&
                                        x.BookId == studentBook.BookId &&
                                        x.Retrived == false)
                                 .FirstOrDefault();

            if (oldstudentbook == null)
            {
                var book = db.Books.Where(x => x.Id == studentBook.BookId).FirstOrDefault();
                if (book == null)
                {
                    return(Json(new Result {
                        Success = false, Messages = $"Book Not Found"
                    }));
                }

                // calculate available books
                int borrowedBooksCount = db.StudentBooks
                                         .Where(s => s.BookId == studentBook.BookId && !s.Retrived)
                                         .Count();
                int availableBooksCount = book.Count - borrowedBooksCount;
                // if there available books
                if (availableBooksCount > 0)
                {
                    studentBook.Date = DateTime.Now;
                    db.StudentBooks.Add(studentBook);
                    db.SaveChanges();
                    return(Json(new Result {
                        Success = true, Messages = $"Student Borrowed Book Successfully"
                    }));
                }
                else
                {
                    return(Json(new Result {
                        Success = false, Messages = $"Sorry This Book Not Available Now"
                    }));
                }
            }
            else
            {
                return(Json(new Result {
                    Success = false, Messages = $"This Student Borrowed this Book before and Must Retrive it first"
                }));
            }
        }
        public IHttpActionResult Put(int id, StudentBook stdBook)
        {
            IHttpActionResult ret = null;

            db.Entry(stdBook).State = EntityState.Modified;
            db.SaveChanges();

            if (stdBook != null)
            {
                ret = Ok(stdBook);
            }
            else
            {
                ret = NotFound();
            }
            return(ret);
        }
        public IHttpActionResult Post(StudentBook stdBook)
        {
            IHttpActionResult ret = null;

            stdBook = db.StudentBooks.Add(stdBook);
            db.SaveChanges();

            if (stdBook != null)
            {
                ret = Created <StudentBook>(Request.RequestUri +
                                            stdBook.BorrowId.ToString(), stdBook);
            }
            else
            {
                ret = NotFound();
            }
            return(ret);
        }
        public IHttpActionResult GetStdBook(int id)
        {
            IHttpActionResult ret;
            StudentBook       stdBook = new StudentBook();

            stdBook = db.StudentBooks.Where(p => p.BorrowId == id).First();

            if (stdBook == null)
            {
                ret = NotFound();
            }
            else
            {
                ret = Ok(stdBook);
            }

            return(ret);
        }
        public IHttpActionResult Delete(int id)
        {
            IHttpActionResult ret     = null;
            StudentBook       stdBook = new StudentBook();

            stdBook = db.StudentBooks.Where(p => p.BorrowId == id).First();
            db.StudentBooks.Remove(stdBook);
            db.SaveChanges();

            if (stdBook != null)
            {
                ret = Ok(true);
            }
            else
            {
                ret = NotFound();
            }
            return(ret);
        }
        // POST: StudentBooks/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public ActionResult Create(/*[Bind(Include = "StudentId,CallNumber,IssueDate,DueDate,IssueStatus,CheckoutDate")] StudentBook studentBook*/
        //    int sid, int callNumber, string issueDate, string dueDate, string status, string checkOutDate)
        //{
        //    StudentBook studentBook=new StudentBook();
        //    //if (ModelState.IsValid)
        //    //{
        //        studentBook.StudentId = sid;
        //        studentBook.CallNumber = callNumber;
        //        studentBook.IssueDate = Convert.ToDateTime(issueDate);
        //        studentBook.DueDate = Convert.ToDateTime(dueDate);
        //        studentBook.IssueStatus = status;
        //        studentBook.CheckoutDate= Convert.ToDateTime(checkOutDate);
        //        db.StudentBooks.Add(studentBook);
        //        db.SaveChanges();
        //    return RedirectToAction("Index");
        //    //}

        //    ViewBag.CallNumber = new SelectList(db.Books, "CallNumber", "ISBN", studentBook.CallNumber);
        //    ViewBag.StudentId = new SelectList(db.Students, "StudentId", "StudentName", studentBook.StudentId);
        //    return View(studentBook);
        //}

        // GET: StudentBooks/Edit/5
        public ActionResult Edit(int?id)
        {
            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            StudentBook studentBook = db.StudentBooks.SingleOrDefault(s => s.Id == id);

            if (studentBook == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CallNumber = new SelectList(db.Books, "CallNumber", "ISBN", studentBook.CallNumber);
            ViewBag.StudentId  = new SelectList(db.Students, "StudentId", "StudentName", studentBook.StudentId);
            ViewBag.Status     = new SelectList(db.StudentBooks, "IssueStatus", "IssueStatus", studentBook.IssueStatus);
            //return View(studentBook);
            return(PartialView("../StudentBooks/_Edit", studentBook));
            //return View(studentBook);
        }
        public IActionResult Insert()
        {
            var student = new Student {
                Name = "wk"
            };

            var book = new Book {
                Name = "C++"
            };

            var sb = new StudentBook {
                Student = student,
                Book    = book
            };

            _db.StudentBooks.Add(sb);
            _db.SaveChanges();

            return(Ok());
        }
Пример #17
0
 public JsonResult <Result> Save([Bind(Include = "StudentId,BookId,Retrived")] StudentBook studentBook)
 {
     try
     {
         // in case of retrive borrowed book must find record in database and change it's Retrived
         if (studentBook.Retrived)
         {
             return(StudentRetriveBook(studentBook));
         }
         else
         {
             return(StudentBorrowBook(studentBook));
         }
     }
     catch (Exception e)
     {
         return(Json(new Result {
             Success = false, Messages = e.Message
         }));
     }
 }
Пример #18
0
        private JsonResult <Result> StudentRetriveBook(StudentBook studentBook)
        {
            var oldstudentbook = db.StudentBooks
                                 .Where(x => x.StudentId == studentBook.StudentId &&
                                        x.BookId == studentBook.BookId &&
                                        x.Retrived == false)
                                 .FirstOrDefault();

            if (oldstudentbook != null)
            {
                oldstudentbook.Retrived = true;
                db.SaveChanges();
                return(Json(new Result {
                    Success = true, Messages = $"Student: {oldstudentbook.Student.Name} Retrived Book: {oldstudentbook.Book.Name} Successfully"
                }));
            }
            else
            {
                return(Json(new Result {
                    Success = false, Messages = $"This student does not borrowed this book before Or borrowed but retrived"
                }));
            }
        }
        public async Task <JsonResult> ReturnBooks(StudentBook studentBook)
        {
            var estudiantes = await studentBookRepository.CreateAsync(configuration["APIBorrowed:BaseUrl"] + Util.ReturnBooks, studentBook);

            return(Json(new { Data = estudiantes }));
        }