public ThoughtDto GetThought(int id) { using (context) { Thought thought = context.Thoughts .SingleOrDefault(t => t.ThoughtId == id); ThoughtDto thoughtDto = Mapper.Map <Thought, ThoughtDto>(thought); return(thoughtDto); } }
public Boolean AddThought([FromBody] AddThoughtViewModel thought) { try { var thoughtDto = new ThoughtDto() { User = Models.Entities.User.GetDefaultUser(), Description = thought.Description, Timeframe = new Timeframe(thought.TimeframeType, thought.DateTime) }; thoughtService.Save(thoughtDto); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }
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(); } } }