Esempio n. 1
0
        public ActionResult Create(IdeaPostViewModel idea)
        {
            var userManager = new UserManager<User>(new UserStore<User>(new UserVoiceSystemDbContext()));
            var newIdea = new Idea()
            {
                Title = new HtmlSanitizer().Sanitize(idea.Title),
                Description = new HtmlSanitizer().Sanitize(idea.Description)
            };

            var userId = this.User.Identity.GetUserId();
            if (userId != null)
            {
                var user = userManager.FindById(userId);
                newIdea.AuthorIpAddress = user.IpAddress;
            }
            else
            {
                newIdea.AuthorIpAddress = this.GetRandomIpAddress();
            }

            this.ideas.Add(newIdea);
            this.ideas.SaveChanges();

            return this.RedirectToAction("Index", "Home");
        }
Esempio n. 2
0
        public ActionResult Delete(int id)
        {
            var idea = this.ideas.GetById(id);
            var userManager = new UserManager<User>(new UserStore<User>(new UserVoiceSystemDbContext()));
            var userId = this.User.Identity.GetUserId();
            var user = userManager.FindById(userId);

            if (user.IpAddress != idea.AuthorIpAddress)
            {
                return this.RedirectToAction("Error", "Home");
            }

            this.ideas.Delete(idea);
            this.ideas.SaveChanges();
            return this.RedirectToAction("Index", "Home");
        }