public ActionResult Edit(Idea idea) { //TODO: Validation //TODO: Security //TODO: Images var old = _ideas.Get(idea.Id); old.Title = idea.Title; old.Description = idea.Description; old.Status = idea.Status; _ideas.Save(); return RedirectToAction("Index", idea.Id); }
public ActionResult New(Idea idea) { var user = _users.GetUserFromUserIdentity(Request.GetIdentity()); if (user == null) return Redirect("/"); idea.Author = user; idea.Time = DateTime.UtcNow; idea.Status = _settings.IdeaStatusDefault; //IEnumerable<string> keys = Context.Request.Form; //var parameters = keys.Where(c => c.StartsWith("imageId")); //var ids = parameters.Select(c => Context.Request.Form[c].ToString()).Cast<string>(); //var images = ids.Select(id => _imageRepository.Get(Convert.ToInt32(id))); //idea.Images = images.ToList(); if (idea.Votes.Any(u => u.UserId == user.Id)) idea.UserHasVoted = true; _ideas.Add(idea); return RedirectToAction("Index", new { id = idea.Id }); }
public ActionResult Uservoice(string channel, string forumid, string apikey, bool trusted) { var client = new WebClient(); var suggestions = GetSuggestions(client, channel, forumid, apikey, trusted); foreach (var s in suggestions) { string title = s.title; //If the idea exists, skip it if (_ideas.FindBy(i => i.Title == title).Any()) continue; string date = s.created_at; var idea = new Idea { Title = title, Description = s.text, Time = DateTime.Parse(date.Substring(0, date.Length - 5)), }; string status = string.Empty; switch ((string)s.state) { case "approved": status = "Active"; break; case "closed": status = s.status.key == "completed" ? "Completed" : "Declined"; break; default: status = "New"; break; } idea.Status = status; //Get the author, or create string name = s.creator.name; var existing = _users.FindBy(u => u.UserName == name).FirstOrDefault(); if (existing != null) idea.Author = existing; else { idea.Author = NewUser(s.creator); _users.Add(idea.Author); } _ideas.Add(idea); //Process all comments var comments = GetComments(client, (string)s.id, channel, forumid, apikey, trusted); foreach (var c in comments) { string commentdate = c.created_at; var comment = new Comment { Time = DateTime.Parse(commentdate), Text = c.text }; string commentname = c.creator.name; existing = _users.FindBy(u => u.UserName == commentname).FirstOrDefault(); if (existing != null) comment.User = existing; else { comment.User = NewUser(c.creator); _users.Add(comment.User); } _activities.Add(idea.Id, comment); } //Process all votes var votes = GetVotes(client, (string)s.id, channel, forumid, apikey, trusted); foreach (var v in votes) { string votername = v.user.name; string votesfor = v.votes_for; int vote; if (Int32.TryParse(votesfor, out vote)) { existing = _users.FindBy(u => u.UserName == votername).FirstOrDefault(); if (existing != null) _ideas.Vote(idea.Id, existing.Id, vote); else { var author = NewUser(v.user); _users.Add(author); _ideas.Vote(idea.Id, author.Id, vote); } } } } return Redirect("/admin"); }