Пример #1
0
        public ActionResult DeleteAccount(int id)
        {
            RSSUser p = Db.users.Where(c => c.Id == id).FirstOrDefault();

            if (p != null)
            {
                Db.Entry(p).State = System.Data.Entity.EntityState.Deleted;
                Db.SaveChanges();
            }
            return(RedirectToAction("Login"));
        }
Пример #2
0
        public ActionResult Logout()
        {
            Session["isadmin"] = false;
            Session["login"]   = false;
            int     uid  = (int)Session["userid"];
            RSSUser user = Db.users.Where(c => c.Id == uid).FirstOrDefault();

            if (user != null)
            {
            }


            return(RedirectToAction("Login"));
        }
Пример #3
0
        public ActionResult GetFeedList()
        {
            int     userid = (int)Session["userid"];
            RSSUser user   = Db.users.Where(c => c.Id == userid).FirstOrDefault();

            if (user != null)
            {
                user.subscriptions  = Db.channels.Where(c => c.userId == user.Id).ToList();
                user.currentChannel = Db.channels.Where(c => c.isCurrent == true).FirstOrDefault();
                user.categories     = Db.categories.Where(c => c.userId == user.Id).ToList();

                user.currentCategory = Db.categories.Where(c => c.isCurrent == true).FirstOrDefault();
            }
            return(PartialView("FeedList", user));
        }
Пример #4
0
        public ActionResult Create(RSSUser model)
        {
            if (ModelState.IsValid)
            {
                Db.users.Add(model);
                Db.SaveChanges();

                return(RedirectToAction("Login"));
            }
            else
            {
                ModelState.AddModelError("", "One or more issues were found with your submission. Please try again.");
            }
            //If we got here, it means that the model's state is invalid.  Simply return
            //to the create page and display any errors.
            return(View("Login", model));
        }
Пример #5
0
        public ActionResult Edit(RSSUser model)
        {
            //again, check modelstate to make sure everything went okay
            if (ModelState.IsValid)
            {
                //Because the item already exists in the DB, we want to tell EF that
                //one of its models has been changed.  We use this somewhat strange syntax to
                //accomplish this task.
                Db.Entry(model).State = System.Data.Entity.EntityState.Modified;

                //Again, the above command adds the request to a queue.  To execute the queue,
                //we need to call SaveChanges()
                Db.SaveChanges();

                //when complete, redirect to Index
                return(RedirectToAction("Index"));
            }

            //Things must've went bad, so send back to the Create view.
            return(View("Create", model));
        }
Пример #6
0
        //
        // GET: /RSS/
        public ActionResult RSSIndex()
        {
            int     userid = (int)Session["userid"];
            RSSUser user   = Db.users.Where(c => c.Id == userid).FirstOrDefault();
            parser  Pars   = new parser();

            if (user != null)
            {
                user.subscriptions  = Db.channels.Where(c => c.userId == user.Id).ToList();
                user.currentChannel = Db.channels.Where(c => c.isCurrent == true).FirstOrDefault();
                user.categories     = Db.categories.Where(c => c.userId == user.Id).ToList();

                user.currentCategory = Db.categories.Where(c => c.isCurrent == true).FirstOrDefault();
            }

            Pars.channels = user.subscriptions;
            if (user.currentChannel != null)
            {
                //user.currentChannel.item = Db.articles.Where(a => a.channelId == user.currentChannel.id).ToList();
                if (user.currentChannel.item.Count == 0)
                {
                    Pars.parseOneFeed(user.currentChannel.title);
                    channel ch = Pars.channels.Where(c => c.title == user.currentChannel.title).FirstOrDefault();
                    if (ch != null)
                    {
                        user.currentChannel.item = ch.item;
                    }

                    user.currentArticle = (string)Session["currentarticle"];
                }
            }
            if (user.currentChannel == null)
            {
                user.currentChannel = new channel();
            }


            return(View("RSSIndex", user));
        }
Пример #7
0
        public ActionResult Edit(int id = -1)
        {
            if (id < 0)
            {
                id = (int)Session["userid"];
            }
            //Find the person in the DB.  Use the supplied "id" integer as a reference.
            RSSUser somePerson = Db.users
                                 .Where(p => p.Id == id) //this line says to find the person whose ID matches our parameter
                                 .FirstOrDefault();      //FirstOrDefault() returns either a singluar Person object or NULL

            //If we got NULL, it must mean that we were supplied an incorrect ID.
            //In this case, redirect to HomeController's Index action.
            if (somePerson == null)
            {
                return(RedirectToAction("Index"));
            }

            //If we're here, then we must have a valid person.  Send to the "Create" view because
            //create and edit are kind of the same thing.  The 2nd parameter is the model that
            //we will be sending to the Create view.
            return(View("Create", somePerson));
        }
Пример #8
0
        public ActionResult Login(RSSUser model)
        {
            int  uId   = 0;
            bool found = false;

            Session["userid"]         = null;
            Session["canwrite"]       = false;
            Session["isadmin"]        = false;
            Session["currentarticle"] = "";


            foreach (RSSUser p in Db.users)
            {
                if (model.Email == p.Email && model.Password == p.Password)
                {
                    uId = p.Id;


                    Session["userid"]       = p.Id;
                    Session["name"]         = p.FirstName + " " + p.LastName;
                    Session["login"]        = true;
                    Session["ScrollHeight"] = 0;
                    if (p.isAdmin == true)
                    {
                        Session["isadmin"] = true;
                    }
                    Db.currentUser = p;
                    found          = true;


                    if (Db.channels != null)
                    {
                        foreach (channel ch in Db.channels)
                        {
                            ch.isCurrent = false;
                        }
                    }
                    if (Db.users != null)
                    {
                        foreach (RSSUser us in Db.users)
                        {
                            us.currentCategory = null;
                            us.currentChannel  = null;
                            us.currentArticle  = null;
                        }
                    }
                    if (Db.categories != null)
                    {
                        foreach (Categories cat in Db.categories)
                        {
                            cat.isCurrent = false;
                        }
                    }

                    Db.SaveChanges();
                }
            }
            if (!found)
            {
                foreach (string key in ModelState.Keys)
                {
                    ModelState[key].Errors.Clear();
                }

                ModelState.AddModelError("", "Invalid User Name / Password");
                return(View("Login"));
            }
            Db.SaveChanges();
            //return RedirectToAction("Login");
            //return View("MyBlogs", new { model = db.CurrentBlogger });
            return(RedirectToAction("RSSIndex", "RSS"));
        }