public CerealRepo() { int x = 1; foreach (string line in myFile) { string[] column = line.Split(","); var cereal = new Cereal { Id = x++, Name = column[0], Manufacturer = column[1], Type = column[2], Calories = Convert.ToDouble(column[3]), Protein = Convert.ToDouble(column[4]), Fat = Convert.ToDouble(column[5]), Sodium = Convert.ToDouble(column[6]), Fiber = Convert.ToDouble(column[7]), Carbo = Convert.ToDouble(column[8]), Sugars = Convert.ToDouble(column[9]), Potassium = Convert.ToDouble(column[10]), Vitamins = Convert.ToInt32(column[11]), Shelf = Convert.ToInt32(column[12]), Weight = Convert.ToDouble(column[13]), Cups = Convert.ToDouble(column[14]), Rating = Convert.ToDouble(column[15]), }; cereal = TypeOfCereal(cereal); Cereals.Add(Manufacturer(cereal)); } }
public IEnumerable <Cereal> PopulateCerealsTable() { List <Cereal> cereals = new List <Cereal>(); foreach (string line in myFile) { string[] column = line.Split(","); var cereal = new Cereal { Name = column[0], Manufacturer = column[1], Type = column[2], Calories = Convert.ToDouble(column[3]), Protein = Convert.ToDouble(column[4]), Fat = Convert.ToDouble(column[5]), Sodium = Convert.ToDouble(column[6]), Fiber = Convert.ToDouble(column[7]), Carbo = Convert.ToDouble(column[8]), Sugars = Convert.ToDouble(column[9]), Potassium = Convert.ToDouble(column[10]), Vitamins = Convert.ToInt32(column[11]), Shelf = Convert.ToInt32(column[12]), Weight = Convert.ToDouble(column[13]), Cups = Convert.ToDouble(column[14]), Rating = Convert.ToDouble(column[15]), }; cereal = TypeOfCereal(cereal); cereals.Add(Manufacturer(cereal)); } return(cereals); }
private Cereal Manufacturer(Cereal cereal) { if (cereal.Manufacturer == "A") { cereal.Manufacturer = "American Home Food Products"; } else if (cereal.Manufacturer == "G") { cereal.Manufacturer = "General Mills"; } else if (cereal.Manufacturer == "K") { cereal.Manufacturer = "Kelloggs"; } else if (cereal.Manufacturer == "N") { cereal.Manufacturer = "Nabisco"; } else if (cereal.Manufacturer == "P") { cereal.Manufacturer = "Post"; } else if (cereal.Manufacturer == "Q") { cereal.Manufacturer = "Quaker Oats"; } else if (cereal.Manufacturer == "R") { cereal.Manufacturer = "Ralston Purina"; } return(cereal); }
public void ShouldAddCerealToListEnd() { CerealList testList = Program.CreateInitialList(); Cereal frostedFlakes = new Cereal("Frosted Flakes"); testList.AppendCereal(frostedFlakes); string[] testArr = testList.ListToArr(6); Assert.Equal("Frosted Flakes", testArr[5]); }
public void SetInfoTarget(string target, Cereal cer) { sendingInfo = true; infoTarget = target; c = cer; c.Begin(this); c.dr = this; //Debug.Log("is dr is null: " + (c.dr == null)); //Debug.Log("set info target"); }
public void ShouldAddCerealAfterFruitLoops() { CerealList testList = Program.CreateInitialList(); Cereal frostedFlakes = new Cereal("Frosted Flakes"); testList.AddAfter(frostedFlakes, "Fruit Loops"); string[] testArr = testList.ListToArr(6); Assert.Equal("Frosted Flakes", testArr[2]); Assert.Equal("Fruit Loops", testArr[1]); }
/// <summary> /// Handle the <see cref="HarvestField"/> command. /// </summary> /// <param name="command">The <see cref="ICommand"/> to process.</param> /// <returns>The result object.</returns> public async Task HandleAsync(HarvestField command) { await Task.Delay(1000); Cereal cereal = command.Field.Harvest(); var fieldHarvested = new FieldHarvested(command.Field, cereal); await this.CommandContext.PublishAsync(fieldHarvested); }
private Cereal TypeOfCereal(Cereal cereal) { if (cereal.Type == "H") { cereal.Type = "Hot"; } else { cereal.Type = "Cold"; } return(cereal); }
void OnTriggerStay2D(Collider2D other) { if (!autoStarting && !tagStarted && Input.GetKeyDown(KeyCode.Return)) { if (dr == null) { initDR(); } string tagName = other.tag; Debug.Log(tagName); switch (tagName) { case "DiningTable": Debug.Log("dining"); if (other.gameObject != null) { Cereal c = other.gameObject.GetComponent <Cereal>(); if (c != null) { dr.SetInfoTarget("cereal", c); cerealing = true; } } break; default: dr.DisableInfo(); cerealing = false; break; } if (dr.Begin(tagName)) { //_playerController.busy = true; _playerController.playerMoving = false; _playerController.busy = true; tagStarted = true; Debug.Log("beginning " + tagName); } else { //_playerController.busy = false; _playerController.playerMoving = true; _playerController.busy = false; tagStarted = false; Debug.Log("can't begin " + tagName); } } }
public void AddCereal(Cereal cereal) { using (var ctx = new MyCerealContext()) { try { ctx.Cereals.Add(cereal); ctx.SaveChanges(); } catch (Exception e) { Log.Error("AddCereal failed: " + e.InnerException); } } }
/// <summary> /// Creates a list of cereals to start the user off /// Also useful for testing /// </summary> /// <returns>A CerealList with a set of Cereal nodes already in it</returns> public static CerealList CreateInitialList() { Cereal LuckyCharms = new Cereal("Lucky Charms"); CerealList StarterList = new CerealList(LuckyCharms); Cereal AppleJacks = new Cereal("Apple Jacks"); Cereal Trix = new Cereal("Trix"); Cereal FruitLoops = new Cereal("Fruit Loops"); Cereal CocoaPebbles = new Cereal("Cocoa Pebbles"); StarterList.AddCereal(AppleJacks); StarterList.AppendCereal(Trix); StarterList.AddBefore(FruitLoops, "Lucky Charms"); StarterList.AddAfter(CocoaPebbles, "Lucky Charms"); return(StarterList); }
public void DeleteMuesli(Cereal selectedCereal) { using (var ctx = new MyCerealContext()) { try { ctx.Cereals.Remove(selectedCereal); ctx.SaveChanges(); } catch (Exception e) { Log.Error("DeleteMuesli failed: " + e.InnerException); } } }
/// <summary> /// Reverses a CerealList in place /// </summary> /// <param name="LL">The Linked List (CerealList in this case) to be reversed</param> /// <returns>The list that was input, which will be reversed</returns> public static CerealList ReverseLL(CerealList LL) { LL.Current = LL.Head; Cereal tempPrev = null; while (LL.Current.Next != null) { Cereal tempNext = LL.Current.Next; LL.Current.Next = tempPrev; tempPrev = LL.Current; LL.Current = tempNext; } LL.Current.Next = tempPrev; LL.Head = LL.Current; return(LL); }
public IHttpActionResult Get(int?id) { Cereal instance = db.Cereals.Find(id); if (id == null) { return(BadRequest()); } if (instance == null) { return(NotFound()); } //Return a 200 status with an instance of a model return(Ok(instance)); }
public override void Up() { var systemPath = AppDomain.CurrentDomain.BaseDirectory + @"..\App_Data\data.csv"; var openfile = File.ReadAllLines(systemPath); foreach (string row in openfile) { var data = row.Split(','); Cereal newCereal = new Cereal { Name = data[0], Manufacturer = data[1] }; db.Cereals.Add(newCereal); } db.SaveChanges(); // --------------------- :) throw new Exception("cookies"); }
public void UpdateCereal(Cereal cereal) { using (var ctx = new MyCerealContext()) { try { var old = ctx.Cereals.First(c => c.CerealId == cereal.CerealId); old.Name = cereal.Name; old.CreatedOn = cereal.CreatedOn; old.Ingredients = cereal.Ingredients; old.Price = cereal.Price; ctx.SaveChanges(); } catch (Exception e) { Log.Error("UpdateCereal failed: " + e.InnerException); } } }
static void PerformAction(char pick, CerealList MyCereal) { Cereal newCer = null; string oldCer = null; Console.WriteLine("\n"); switch (pick) { case '1': newCer = new Cereal(GetNewCereal()); MyCereal.AddCereal(newCer); break; case '2': newCer = new Cereal(GetNewCereal()); MyCereal.AppendCereal(newCer); break; case '3': newCer = new Cereal(GetNewCereal()); Console.WriteLine("Which cereal should come after this new one?"); oldCer = Console.ReadLine(); MyCereal.AddBefore(newCer, oldCer); break; case '4': newCer = new Cereal(GetNewCereal()); Console.WriteLine("Which cereal should come before this new one?"); oldCer = Console.ReadLine(); MyCereal.AddAfter(newCer, oldCer); break; case '5': MyCereal.PrintList(); break; default: Console.WriteLine("Sorry, that wan't an option."); break; } UserLoop(MyCereal); }
public ObservableCollection <Ingredient> GetIngredientList(Cereal cereal) { using (var ctx = new MyCerealContext()) { IQueryable <Ingredient> ingredients = null; try { ingredients = from ing in ctx.Ingredients join category in ctx.Categories on ing.Category.CategoryId equals category.CategoryId select ing; } catch (Exception e) { Log.Error("GetIngredientList failed: " + e.InnerException); } return(new ObservableCollection <Ingredient>(ingredients.Where(i => i .Cereals.Contains(cereal)))); } }
public void FindProductsTest() { Salad testSalad = new Salad("TestSalad"); Product product1 = new Cereal("Rice", 900, 12, 56, 5); Product product2 = new Vegetable("Onion", 60, 12, 2, 5); Product product3 = new Vegetable("Something", 35, 34, 3, 65); Product product4 = new Sauce("SourCream", 200, 5, 3, 85); testSalad.ProductSalad.Add(product1); testSalad.ProductSalad.Add(product2); testSalad.ProductSalad.Add(product3); testSalad.ProductSalad.Add(product4); List <Product> testFindedProduct = testSalad.FindProducts(0, 150); List <Product> correctFindedProduct = new List <Product> (); correctFindedProduct.Add(product2); correctFindedProduct.Add(product3); CollectionAssert.AreEqual(correctFindedProduct, testFindedProduct); }
public void CompareToTest() { Salad testSalad = new Salad("TestSalad"); Product product1 = new Cereal("Rice", 900, 12, 56, 5); Product product2 = new Sauce("SourCream", 200, 5, 3, 85); Product product3 = new Vegetable("Onion", 60, 12, 2, 5); testSalad.ProductSalad.Add(product1); //3096 testSalad.ProductSalad.Add(product2); //508 testSalad.ProductSalad.Add(product3); //123.6 testSalad.ProductSalad.Sort(); List <Product> testListProduct = testSalad.ProductSalad; List <Product> correctListProduct = new List <Product>(); correctListProduct.Add(product3); correctListProduct.Add(product2); correctListProduct.Add(product1); CollectionAssert.AreEqual(correctListProduct, testListProduct); }
public override void Up() { var csvPath = AppDomain.CurrentDomain.BaseDirectory + @"..\App_Data\Data.csv"; var openFile = File.ReadAllLines(csvPath); using (var db = new ApplicationContext()) { foreach (string row in openFile) { var data = row.Split(','); Cereal newCereal = new Cereal { Name = data[0], Manufacturer = data[1] }; db.Cereals.Add(newCereal); } db.SaveChanges(); } //---------------// //throw new Exception("cookies"); }
/// <summary> /// Merges two Linked Lists by zippering the second cereal list into the first /// </summary> /// <param name="listA">A list of Cereals</param> /// <param name="listB">A second list of Cereals</param> /// <returns>The first list which is now combined with the second</returns> public static CerealList Merge(CerealList listA, CerealList listB) { listA.Current = listA.Head; listB.Current = listB.Head; while (listA.Current.Next != null && listB.Current.Next != null) { Cereal tempA = listA.Current.Next; Cereal tempB = listB.Current.Next; listA.Current.Next = listB.Current; listB.Current.Next = tempA; listA.Current = tempA; listB.Current = tempB; } if (listA.Current.Next == null) { listA.Current.Next = listB.Current; } else { listB.Current.Next = listA.Current.Next; listA.Current.Next = listB.Current; } return(listA); }
public GrindFlour(Cereal cereal) { this.Cereal = cereal; }
public FlourGrinded(Cereal cereal, Flour flour) { this.Cereal = cereal; this.Flour = flour; }
public FieldHarvested(Field field, Cereal cereal) { this.Field = field; this.Cereal = cereal; }
public CerealViewModel(Cereal cereal) { Cereal = cereal; }
public MyCerealViewModel(Cereal c) { Cereal = c; }