public static FoodDescription GetNewFoodDescription() { var item = new FoodDescription { Id = GetNumber(), Name = GetName(), Description = GetDescription(), SomeDate = DateTimeOffset.Now }; return item; }
public async Task<FoodDescription> UpdateOrAddFoodDescriptionAsync(IWorkUnit workUnit, FoodDescription foodDescription) { if (workUnit == null) { throw new ArgumentNullException("workUnit"); } if (foodDescription == null) { throw new ArgumentNullException("foodDescription"); } var exists = await workUnit.Collection<FoodDescription>() .Select(f => f.Id) .FirstOrDefaultAsync(n => n == foodDescription.Id); workUnit.GetContext<FoodContext>().Entry(foodDescription).State = exists == null ? EntityState.Added : EntityState.Modified; return foodDescription; }