public void AddStory(StoriesModelForm story) { story.StoryTime = DateTime.Now; // TODO add the actual logged in user example string userName = User.Identity.Name context.Story.Add(story); context.SaveChanges(); }
public IActionResult UpdateStory(string id, [FromBody] PatchViewModel patchVm) { // TODO: Add support for more ops: remove, copy, move, test StoriesModelForm story = storiesRepo.GetStoryById(id); switch (patchVm.Path) { case "title": story.StoryTitle = patchVm.Value; break; case "time": story.StoryTime = Convert.ToDateTime(patchVm.Value); break; case "poster": story.Poster.Name = patchVm.Value; // TODO: manage author collection break; case "topic": story.StoryTopic = patchVm.Value; break; case "text": story.StoryText = patchVm.Value; break; default: return(BadRequest()); } storiesRepo.Edit(story); return(Ok(story)); }
public IActionResult DeleteStory(string id) { StoriesModelForm story = storiesRepo.GetStoryById(id); if (story != null) { storiesRepo.Delete(story); return(NoContent()); // Successfully completed, no data to send back } else { return(NotFound()); } }
public IActionResult AddStory([FromBody] StoriesModelForm StoryVm) { if (StoryVm != null) { StoriesModelForm story = new StoriesModelForm { StoryTitle = StoryVm.StoryTitle, StoryTopic = StoryVm.StoryTopic, StoryText = StoryVm.StoryText, Poster = StoryVm.Poster, StoryTime = StoryVm.StoryTime }; return(Ok(story)); } else { return(BadRequest()); } }
public IActionResult Replace(string id, [FromBody] StoriesModelForm StoryVm) { if (StoryVm != null) { StoriesModelForm story = storiesRepo.GetStoryById(id); story.StoryTitle = StoryVm.StoryTitle; story.StoryTopic = StoryVm.StoryTopic; story.StoryText = StoryVm.StoryText; story.Poster.Name = StoryVm.Poster.Name; story.StoryTime = StoryVm.StoryTime; storiesRepo.Edit(story); return(Ok(story)); } else { return(BadRequest()); } }
public void Delete(StoriesModelForm story) { var comments = context.Comments.ToList(); foreach (CommentModel comment in comments) // added to delete all comments of a story before deleting the story { foreach (CommentModel storycomment in story.Comments) { if (comment.CommentId == storycomment.CommentId) { context.Comments.Remove(comment); context.SaveChanges(); } } } context.Story.Remove(story); context.SaveChanges(); }
public List <AppUser> GetPosterByStory(StoriesModelForm story) { throw new NotImplementedException(); }
public void Edit(StoriesModelForm story) { context.Story.Update(story); context.SaveChanges(); }