예제 #1
0
        public async Task <Habit> Insert(Habit habit)
        {
            var entity = new Infrastructure.Data.Context.Habit
            {
                Id          = habit.Id,
                Created     = habit.Created,
                Description = habit.Description,
                Name        = habit.Name,
                UserId      = habit.UserId
            };
            await _db.Habits.AddAsync(entity);

            await _db.SaveChangesAsync();

            return(entity.ToDomain());
        }
예제 #2
0
        public async Task <User> LoadOrInsert(Guid id)
        {
            var entity = await _db.Users.Where(z => z.Id == id).SingleOrDefaultAsync();

            if (entity == null)
            {
                entity = new Context.User
                {
                    Id = id
                };
                await _db.Users.AddAsync(entity);

                await _db.SaveChangesAsync();
            }

            return(entity.ToDomain());
        }