public ActionResult <StoryCreationViewModel> Post([FromBody] UpdateStoryViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var ownerId = HttpContext.User.Identity.Name; var creationTime = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds(); var storyId = Guid.NewGuid().ToString(); var story = new Story { Id = storyId, Title = model.Title, Content = model.Content, Tags = model.Tags, CreationTime = creationTime, LastEditTime = creationTime, OwnerId = ownerId, Draft = true }; storyRepository.Add(story); storyRepository.Commit(); return(new StoryCreationViewModel { StoryId = storyId }); }
public ActionResult Patch(string id, [FromBody] UpdateStoryViewModel model) { //if (!ModelState.IsValid) return BadRequest(ModelState); //var ownerId = HttpContext.User.Identity.Name; //if (!storyRepository.IsOwner(id, ownerId)) return Forbid("You are not the owner of this story"); //var newStory = storyRepository.GetSingle(id); //newStory.Title = model.Title; //newStory.LastEditTime = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds(); //newStory.Tags = model.Tags; //newStory.Content = model.Content; //storyRepository.Update(newStory); //storyRepository.Commit(); return(NoContent()); }