private static DishCategory FromRow(DishCategoryRow row) { return(new DishCategory(new DishCategoryId(row.Id), new RestaurantId(row.RestaurantId), row.Name )); }
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)); }
private static void ToRow(DishCategory obj, DishCategoryRow row) { row.Id = obj.Id.Value; row.RestaurantId = obj.RestaurantId.Value; row.Name = obj.Name; }