/// <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();
        }
Esempio n. 2
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();
        }
Esempio n. 3
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();
        }