public async void Save(ThoughtDto thoughtDto) { using (context) { Thought thought; if (thoughtDto.ThoughtId > 0) { thought = context.Thoughts .SingleOrDefaultAsync(t => t.ThoughtId == thoughtDto.ThoughtId) .Result; thought.Update( thoughtDto.Description, (int)thoughtDto.Timeframe.TimeframeType, thoughtDto.Timeframe.TimeframeDateTime, thoughtDto.Project); try { context.Update <Thought>(thought); await context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e); throw; } } else { thought = Thought.Create(thoughtDto.Description, thoughtDto.SortId, (int)thoughtDto.Timeframe.TimeframeType, thoughtDto.Timeframe.TimeframeDateTime, thoughtDto.Project); context.Thoughts.Add(thought); context.SaveChanges(); } } }