/// <summary> /// Creates a new ViewTagModel object given the original tag. /// </summary> /// <param name="tag"></param> public ViewTagModel(Tag tag) { if (tag == null) { throw new ArgumentNullException("tag"); } this.Id = tag.Id; this.Name = tag.Name; this.MarkdownBody = tag.Body; this.Subscriptions = tag.Subscribers.Count; this.DateCreated = tag.DateCreated; }
public ActionResult Create(QuestionModel question) { if (ModelState.IsValid) { string[] seperatedTags = question.Tags.Split(new[] { ' ', ',', '.' }, StringSplitOptions.RemoveEmptyEntries); List<Tag> tags = new List<Tag>(seperatedTags.Length); foreach (string tag in seperatedTags) { Tag t = dataContext.Tags.FirstOrDefault(a => a.Name.Equals(tag, StringComparison.OrdinalIgnoreCase)); if (t == null) { t = new Tag(tag, null, ControllerHelper.GetAuthenticatedUser(dataContext)); } tags.Add(t); } Question q = new Question(ControllerHelper.GetAuthenticatedUser(dataContext), question.Body, question.Title, tags); dataContext.Questions.Add(q); dataContext.SaveChanges(); return RedirectToAction("Question", new { id = q.Id }); } else { return View(); } }