コード例 #1
0
 // GET: Account
 /// <summary>
 /// Function responsible for display registred Users
 /// </summary>
 /// <returns>View</returns>
 public ActionResult Index()
 {
     using (TajnyProjektDbContext db = new TajnyProjektDbContext())
     {
         return View(db.Users.ToList());
     }
   
 }
コード例 #2
0
        public ActionResult Login(User logUser)
        {
            using (TajnyProjektDbContext db = new TajnyProjektDbContext())
            {
                User usr = db.Users.FirstOrDefault(x => x.Password == logUser.Password);
                if (usr != null)
                {
                    Session["UserID"] = usr.UserId.ToString();
                    Session["Username"] = usr.Name.ToString();
                 return RedirectToAction("LoggedIn");
                }

                    ModelState.AddModelError("","User Name or Password incorrect");
                
            }
            return View();
        }
コード例 #3
0
        /// <summary>
        /// Function responsible for display view with temporary availability , creat view with proposition , save to database book if readed. Class redirect to History Action if user click add book to history
        /// </summary>
        /// <returns>View</returns>
        public ActionResult Index()
        {
            try
            {
                logUserId = Session["UserId"].ToString();
            }
            catch (Exception e)
            {
                return RedirectToAction("Index", "Home");

            }


            var time = Convert.ToInt32(Request["time"]);
            var bookName = Request["check"];
            var booksProposion = new Dictionary<string, double>();
            TajnyProjektDbContext db = new TajnyProjektDbContext();

         
            var User = db.Users.FirstOrDefault(x => x.UserId == logUserId);
            var FavouritesBooks = db.Books.Where(x => x.Kind == User.GradeBook).ToList();

            if (time != 0 )
            {
                double value =0;
                foreach (var book in FavouritesBooks)
                {
                     value = book.PageNumber/time;
                    booksProposion.Add(book.Title,value);
                }
                booksProposion.OrderBy(x=>x.Value);
                return View(booksProposion);
            }
            if (bookName != null)
            {
                BookReadHistory newhistory = new BookReadHistory();
                var book = db.Books.FirstOrDefault(x => x.Title == bookName);
                newhistory.BookTitle = book.Title;
                newhistory.UserId = Session["UserId"].ToString();
                db.BookReadHistories.Add(newhistory);
                db.SaveChanges();
                return RedirectToAction("Index", "History");
            }
            return View();
        }
コード例 #4
0
        // GET: Edit
        /// <summary>
        /// Function responsible for display Edit page
        /// </summary>
        /// <returns>View</returns>
        public ActionResult Edit()
        
        {
            try
            {
                userId = Session["UserId"].ToString();
            }
            catch (Exception e)
            {
                return RedirectToAction("Index", "Home");
             
            }
            
            TajnyProjektDbContext db = new TajnyProjektDbContext();
            User usr = db.Users.FirstOrDefault(x => x.UserId == userId);  

            return View();
        }
コード例 #5
0
        // GET: History
        /// <summary>
        /// Class responsible for generate View with read books by user
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            try
            {
                logUserId = Session["UserId"].ToString();
            }
            catch (Exception e)
            {
                return RedirectToAction("Index", "Home");

            }
            
            TajnyProjektDbContext db = new TajnyProjektDbContext();
            var User = db.Users.FirstOrDefault(x => x.UserId == logUserId);
            var userHistory = db.BookReadHistories.Where(x => x.UserId == User.UserId).ToList();

            return View(userHistory);
        }
コード例 #6
0
        public ActionResult Register(User user)
        {
            if (ModelState.IsValid)
            {
                using (TajnyProjektDbContext db = new TajnyProjektDbContext())
                {
                    const string chars = "0123456789";
                    var random = new Random();
                    user.UserId =random.Next(0,1000).ToString();
                    db.Users.Add(user);
                    db.SaveChanges();
                }
                ModelState.Clear();
                ViewBag.Message = user.Name + " " + user.Surname + " succesfuil registred";
            }

            return View();
        }
コード例 #7
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                using (TajnyProjektDbContext db = new TajnyProjektDbContext())
                {
                    user.UserId = Session["UserId"].ToString();     
                    db.Entry(user).State = EntityState.Modified;
                    db.SaveChanges();
                    
                }
                 ModelState.Clear();
                ViewBag.Message = "Edit Succesfull";
                return RedirectToAction("Edit");
            }


            return View();
        }