コード例 #1
0
 private static DishCategory FromRow(DishCategoryRow row)
 {
     return(new DishCategory(new DishCategoryId(row.Id),
                             new RestaurantId(row.RestaurantId),
                             row.Name
                             ));
 }
コード例 #2
0
        public Task StoreAsync(DishCategory dishCategory, CancellationToken cancellationToken = default)
        {
            return(Task.Factory.StartNew(() =>
            {
                var dbSet = dbContext.DishCategories;

                var row = dbSet.FirstOrDefault(x => x.Id == dishCategory.Id.Value);
                if (row != null)
                {
                    ToRow(dishCategory, row);
                    dbSet.Update(row);
                }
                else
                {
                    row = new DishCategoryRow();
                    ToRow(dishCategory, row);
                    dbSet.Add(row);
                }

                dbContext.SaveChanges();
            }, cancellationToken));
        }
コード例 #3
0
 private static void ToRow(DishCategory obj, DishCategoryRow row)
 {
     row.Id           = obj.Id.Value;
     row.RestaurantId = obj.RestaurantId.Value;
     row.Name         = obj.Name;
 }