Esempio n. 1
0
 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();
 }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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());
            }
        }
Esempio n. 4
0
 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());
     }
 }
Esempio n. 5
0
        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());
            }
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
 public List <AppUser> GetPosterByStory(StoriesModelForm story)
 {
     throw new NotImplementedException();
 }
Esempio n. 8
0
 public void Edit(StoriesModelForm story)
 {
     context.Story.Update(story);
     context.SaveChanges();
 }