/// <summary> /// /// </summary> /// <param name="model"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public async Task PutStoryAsync(EquityStoryContract model) { var updatedStory = await Context.EquityStories.FindAsync(model.Id); if (updatedStory == null) { throw new CannotFindIdException("story", model.Id); } var editedStory = EquityMapper.EquityContractToEntity(model); Context.Entry(updatedStory).CurrentValues.SetValues(editedStory); Context.Entry(updatedStory).State = EntityState.Modified; if (await Context.SaveChangesAsync() <= 0) { throw new CannotSaveToDatabaseException("Story"); } }
/// <summary> /// post new equity story /// </summary> /// /// <param EquityContract="model"></param> /// <returns></returns> public async Task <int> PostStoryAsync(EquityStoryContract model) { if (Context.EquityStories.Find(model.Id) != null) { throw new EntityConflictException("story", model.Id); } var newStory = EquityMapper.EquityContractToEntity(model); Context.EquityStories.Add(newStory); Context.Entry(newStory).State = EntityState.Added; var saved = await Context.SaveChangesAsync(); if (saved <= 0) { throw new CannotSaveToDatabaseException("story"); } var storyId = newStory.Id; return(storyId); }