public IActionResult Create(string categoryName, Topic topic) { if (ModelState.IsValid) { topic.CreatedDate = DateTime.Now; topic.LastUpdatedDate = DateTime.Now; string authorId = context.Users .Where(u => u.UserName == User.Identity.Name) .First() .Id; topic.AuthorId = authorId; if (!context.Categories.Any(c => c.Name == categoryName)) { return(View(topic)); } int categoryId = context.Categories.SingleOrDefault(c => c.Name == categoryName).Id; topic.CategoryId = categoryId; context.Add(topic); context.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(topic)); }
public Post Create(Category category, string title, string content, User author) { //Suzdavame si samiq post Post post = new Post(title, content, category, author); context.Add(post); context.SaveChanges(); return(post); }