/// <summary> /// Main constructor. /// </summary> /// <param name="ingredient"></param> public Ingredients(Ingredients ingredient) { if (MongoManager.ItemExists <Ingredients>(x => x.Name == ingredient.Name)) { throw new Exception($"There is already an ingredient [{ingredient.Name}] - {ingredient.PriceUnit} - [{string.Join(", ", ingredient.Categories)}]."); } BaseQuantity = ingredient.BaseQuantity; Name = ingredient.Name; PriceUnit = ingredient.PriceUnit; Categories = ingredient.Categories; }
/// <summary> /// Create or update the ingredient. /// </summary> public void Save() { bool isNew = _id == ObjectId.Empty; if (!isNew && !MongoManager.ItemExists <Users>(x => x.Login == Login)) { throw new Exception($"There is no user [{Login}]."); } MongoManager.Save(this); log.Information($"{(isNew ? "Added" : "Updated")} user [{Login}] - {_id}."); }
/// <summary> /// Main constructor. /// </summary> /// <param name="recipe"></param> public Recipes(Recipes recipe) { if (MongoManager.ItemExists <Recipes>(x => x.Name == recipe.Name)) { throw new Exception($"There is already a recipe [{recipe.Name}]."); } TimesCooked = recipe.TimesCooked; Type = recipe.Type; UserId = recipe.UserId; LastCooked = recipe.LastCooked; Name = recipe.Name; BestSeasons = recipe.BestSeasons; Ingredients = recipe.Ingredients; }