Exemplo n.º 1
0
        public ActionResult creaetNewBook(Book book)
        {
            if (ModelState.IsValid)
            {
                var context = new ApplicationContextDb();

                context.Books.Add(book);
                context.SaveChanges();
                return(RedirectToAction("Books", "Books"));
            }

            return(View("Create"));
        }
Exemplo n.º 2
0
        public ActionResult borrowBook(Book book)
        {
            var context = new ApplicationContextDb();

            Transaction trans     = new Transaction();
            String      userEmail = HttpContext.User.Identity.Name;
            User        userDb    = context.Users.FirstOrDefault(x => x.Email == userEmail);

            trans.BookId     = book.Id;
            trans.StudentId  = userDb.Id;
            trans.IssuedOn   = new DateTime();
            trans.ReturnDate = new DateTime().AddDays(7);
            trans.Status     = "issued";
            context.Transactions.Add(trans);
            context.SaveChanges();

            Book bookDb = context.Books.FirstOrDefault(x => x.Id == book.Id);

            bookDb.Available = "False";
            context.SaveChanges();
            return(RedirectToAction("Books", "Books"));
        }
Exemplo n.º 3
0
        public ActionResult returnMyBook(Transaction trans)
        {
            if (ModelState.IsValid)
            {
                var         context = new ApplicationContextDb();
                Transaction transDb = context.Transactions.FirstOrDefault(x => x.TransactionId == trans.TransactionId);
                transDb.Status = "Returned";
                Book bookDb = context.Books.FirstOrDefault(x => x.Id == trans.BookId);
                bookDb.Available = "True";
                context.SaveChanges();
            }

            return(RedirectToAction("MyBooks"));
        }
Exemplo n.º 4
0
 public ActionResult updateBookInfo(Book book)
 {
     if (ModelState.IsValid)
     {
         var  context = new ApplicationContextDb();
         Book bookDb  = context.Books.FirstOrDefault(x => x.Id == book.Id);
         bookDb.Title             = book.Title;
         bookDb.Author            = book.Author;
         bookDb.Publisher         = book.Publisher;
         bookDb.YearOfPublication = book.YearOfPublication;
         bookDb.NoOfPages         = book.NoOfPages;
         context.SaveChanges();
         return(RedirectToAction("Books"));
     }
     return(RedirectToAction("Books"));
 }
        public ActionResult updateprofile(User user)
        {
            var context = new ApplicationContextDb();

            if (ModelState.IsValid)
            {
                String userEmail = HttpContext.User.Identity.Name;
                User   userDb    = context.Users.FirstOrDefault(x => x.Id == user.Id);
                userDb.FirstName   = user.FirstName;
                userDb.LastName    = user.LastName;
                userDb.Email       = user.Email;
                userDb.Address     = user.Address;
                userDb.Tfn         = user.Tfn;
                userDb.Dob         = user.Dob;
                userDb.PhoneNumber = user.PhoneNumber;

                context.SaveChanges();
            }

            return(RedirectToAction("Student"));
        }
        public ActionResult creaetNewStudent(User user, FormCollection form)
        {
            var context = new ApplicationContextDb();

            var        getdepartmentList = context.Departments.ToList();
            SelectList departList        = new SelectList(getdepartmentList, "DepartmentId", "DepartmentName");

            ViewBag.departments = departList;


            if (ModelState.IsValid)
            {
                user.RoleId   = 2;
                user.Password = "******";


                context.Users.Add(user);
                context.SaveChanges();
                return(View("Student/Create"));
            }

            return(View("Student/Create"));
        }
Exemplo n.º 7
0
 public void Delete(TEntity Entity)
 {
     Db.Set <TEntity>().Remove(Entity);
     Db.SaveChanges();
 }