Example #1
0
        public ActionResult getBookInfo(int bookId)
        {
            var  context = new ApplicationContextDb();
            Book book    = context.Books.FirstOrDefault(x => x.Id == bookId);

            return(View("View", book));
        }
        public ActionResult getStudent(int studentId)
        {
            var  context  = new ApplicationContextDb();
            User students = context.Users.FirstOrDefault(x => x.Id == studentId);

            return(View("Student/View", students));
        }
Example #3
0
        public ActionResult Books()
        {
            var         context = new ApplicationContextDb();
            List <Book> books   = context.Books.ToList();

            return(View("index", books));
        }
        public ActionResult creaetStudent()
        {
            var        context           = new ApplicationContextDb();
            var        getdepartmentList = context.Departments.ToList();
            SelectList departList        = new SelectList(getdepartmentList, "DepartmentId", "DepartmentName");

            ViewBag.departments = departList;
            return(View("Student/Create"));
        }
Example #5
0
        public ActionResult getMyBookInfo(int transactionId)
        {
            var         context = new ApplicationContextDb();
            Transaction trans   = context.Transactions.FirstOrDefault(x => x.TransactionId == transactionId);



            return(View("MyBookView", trans));
        }
        public ActionResult Student()
        {
            var         context  = new ApplicationContextDb();
            List <User> students = context.Users.ToList();

            List <User> studentsList = (from user in context.Users
                                        where user.RoleId == 2
                                        select user).ToList <User>();

            return(View("Student/index", studentsList));
        }
        public ActionResult Profile()
        {
            var context = new ApplicationContextDb();

            String userEmail = HttpContext.User.Identity.Name;

            User user = context.Users.FirstOrDefault(x => x.Email == userEmail);

            ViewBag.departmentName = user.Department.DepartmentName;


            return(View(user));
        }
Example #8
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"));
        }
Example #9
0
        public ActionResult MyBooks()
        {
            var    context   = new ApplicationContextDb();
            String userEmail = HttpContext.User.Identity.Name;

            User userDb = context.Users.FirstOrDefault(x => x.Email == userEmail);


            List <Transaction> booksList = context.Transactions.Where(x => x.StudentId == userDb.Id).ToList <Transaction>();


            return(View("MyBooks", booksList));
        }
Example #10
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"));
        }
Example #11
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 NotifyStudent(Book book)
        {
            var context = new ApplicationContextDb();

            Transaction trans = context.Transactions.FirstOrDefault(x => x.BookId == book.Id && x.Status == "issued");

            User stud = context.Users.FirstOrDefault(x => x.Id == trans.StudentId);

            EmailSender email = new EmailSender();

            //String toEmail = "*****@*****.**";

            String message = "Please return the book: " + book.Title;

            email.Send(stud.Email, "Monash Library", message);
            return(RedirectToAction("Books", "Dashboard"));
        }
Example #13
0
        public static async Task DispatchDomainEventsAsync(this IMediator mediator, ApplicationContextDb ctx)
        {
            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.DomainEvents != null && x.Entity.DomainEvents.Any());

            var domainEvents = domainEntities
                               .SelectMany(x => x.Entity.DomainEvents)
                               .ToList();

            domainEntities.ToList()
            .ForEach(entity => entity.Entity.ClearDomainEvents());

            foreach (var domainEvent in domainEvents)
            {
                await mediator.Publish(domainEvent);
            }
        }
        public ActionResult Login(User user)
        {
            if (ModelState.IsValid)
            {
                using (var context = new ApplicationContextDb())
                {
                    bool isValid = context.Users.Any(x => x.Email == user.Email && x.Password == user.Password);

                    if (isValid)
                    {
                        FormsAuthentication.SetAuthCookie(user.Email, false);
                        return(RedirectToAction("Home", "Dashboard"));
                    }
                    ModelState.AddModelError("", "Invalid Username and password");
                    return(View());
                }
            }

            return(View());
        }
        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 SendNewsletter(Email email)
        {
            var         file        = email.fileAttachment.InputStream.ReadByte();
            EmailSender emailSender = new EmailSender();

            var context = new ApplicationContextDb();

            List <User> studentList = (from user in context.Users
                                       where user.RoleId == 2
                                       select user).ToList <User>();

            List <string> emailList = new List <string>();

            foreach (User st in studentList)
            {
                emailList.Add(st.Email);
            }

            emailSender.SendMailAttachment(email, emailList);
            return(View("NewsLetter"));
        }
Example #17
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"));
        }
        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"));
        }
 public ClienteCommandRepository(ApplicationContextDb context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }