public void Import(IEnumerable<Ingredients> data) { using (var transaction = this.session.BeginTransaction()) { var ingredientsArray = data.ToArray(); foreach (var ingredient in ingredientsArray) { var databaseIngredient = new Models.Ingredients { IngredientId = ingredient.IngredientId, FoodGroup = ingredient.FoodGroup, UsdaId = ingredient.UsdaId, UnitName = ingredient.UnitName, ManufacturerName = ingredient.ManufacturerName, ConversionType = ingredient.ConversionType, UnitWeight = ingredient.UnitWeight, DisplayName = ingredient.DisplayName, UsdaDesc = ingredient.UsdaDesc }; this.session.Save(databaseIngredient, ingredient.IngredientId); } this.Log.DebugFormat("Created {0} row(s) in Ingredients", ingredientsArray.Count()); transaction.Commit(); this.session.Flush(); } }
public void Import(IEnumerable <Data.DTO.Ingredients> data) { using (var transaction = session.BeginTransaction()) { var d = data.ToArray(); foreach (var row in d) { var dbRow = new Models.Ingredients { IngredientId = row.IngredientId, FoodGroup = row.FoodGroup, UsdaId = row.UsdaId, UnitName = row.UnitName, ManufacturerName = row.ManufacturerName, ConversionType = row.ConversionType, UnitWeight = row.UnitWeight, DisplayName = row.DisplayName, UsdaDesc = row.UsdaDesc }; session.Save(dbRow, row.IngredientId); } Log.DebugFormat("Created {0} row(s) in Ingredients", d.Count()); transaction.Commit(); session.Flush(); } }
public void Import(IEnumerable<Data.DTO.Ingredients> data) { using (var transaction = session.BeginTransaction()) { var d = data.ToArray(); foreach (var row in d) { var dbRow = new Models.Ingredients { IngredientId = row.IngredientId, FoodGroup = row.FoodGroup, UsdaId = row.UsdaId, UnitName = row.UnitName, ManufacturerName = row.ManufacturerName, ConversionType = row.ConversionType, UnitWeight = row.UnitWeight, DisplayName = row.DisplayName, UsdaDesc = row.UsdaDesc }; session.Save(dbRow, row.IngredientId); } Log.DebugFormat("Created {0} row(s) in Ingredients", d.Count()); transaction.Commit(); session.Flush(); } }
public void AddIngredients(Models.Ingredients ingredients, Models.Store store) { if (store != null) { // get the db's version of that restaurant // (can't use Find with Include) DataAccess.Store contextStore = _db.Store.Include(r => r.Ingredients) .First(r => r.Id == store.Id); store.Ingredients.Add(ingredients); contextStore.Ingredients.Add(Map(ingredients)); } else { _db.Add(Map(ingredients)); } }
public ActionResult Create(Models.Ingredients ingredient) { if (!ModelState.IsValid) { return(View(ingredient)); } db.Ingredients.Add(ingredient); try { db.SaveChanges(); } catch (Exception e) { return(View(ingredient)); } return(RedirectToAction("Index")); }
public ActionResult Edit(Models.Ingredients ingredient) { if (!ModelState.IsValid) { return(View(ingredient)); } var originalIngredient = (from i in db.Ingredients where i.Id == ingredient.Id select i).First(); db.Entry(originalIngredient).CurrentValues.SetValues(ingredient); try { db.SaveChanges(); } catch (Exception e) { return(View(ingredient)); } return(RedirectToAction("Index")); }
public static DataAccess.Ingredients Map(Models.Ingredients ingredients) => new DataAccess.Ingredients { Id = ingredients.Id, Name = ingredients.Name, StockNumber = ingredients.StockNumber };
public void UpdateIngredients(Models.Ingredients ingredients) { _db.Entry(_db.Ingredients.Find(ingredients.Id)).CurrentValues.SetValues(Map(ingredients)); }