internal static bool EntitySelection <TEntity>(List <TEntity> entities, out TEntity entity, int tabCount = 0) where TEntity : Entity { if (entities.Count == 0) { entity = null; return(false); } do { CommonClientFunctions.PrintEntities(entities, tabCount); Console.WriteLine($"{entities.Count + 1}) Cancel"); var success = Int32.TryParse(Console.ReadLine(), out int input); if (input > 0 && input <= entities.Count && success) { entity = entities[input - 1]; return(true); } else if (input == entities.Count + 1) { entity = null; return(true); } } while (true); }
private MaterialCount CreateMaterialCount(List <Material> materials) { Console.WriteLine("Pick a material> "); var hasElements = CommonClientFunctions.EntitySelection(materials, out Material material); if (!hasElements) { Console.WriteLine("No Materials Available"); return(null); } if (material is null) { return(null); } Console.Write("Enter a description (Optional)> "); string newDescription = Console.ReadLine(); decimal newUnitCount; do { Console.Write("Enter the number of units of material needed as a whole number> "); Decimal.TryParse(Console.ReadLine(), out newUnitCount); } while (newUnitCount <= 0); return(new MaterialCount() { MaterialId = material.Id, MaterialUnitCount = newUnitCount, Description = newDescription }); }
private void CreateSizeOption(Item item) { List <Material> materials = CommonClientFunctions.ReadMaterials(); var sizeOption = CreateSizeOption(materials); sizeOption.ItemId = item.Id; item.SizeOptions.Add(sizeOption); using var db = new ShopContext(); new DataService(db).Create(sizeOption); }
public void Run() { CommonClientFunctions.Menuing(MenuOptionsAnalysis(), (actionInput) => { switch (actionInput) { case 1: ItemsReport(); break; } }); }
private void ItemsReport() { var items = CommonClientFunctions.ReadItems(); foreach (var item in items) { Console.WriteLine($"Item: {item.Name}"); foreach (var sizeOption in item.SizeOptions) { Console.WriteLine($"\tSize Option: {sizeOption.Size} - " + $"Sell Price: {sizeOption.Price.ToString("C", CultureInfo.CurrentCulture)} - " + $"{sizeOption.TimeToMakeInHours} hours"); //lowest cost materials var minMaterialCost = new List <Tuple <decimal, decimal> >(); var maxMaterialCost = new List <Tuple <decimal, decimal> >(); var avgMaterialCost = new List <Tuple <decimal, decimal> >(); bool hasMaterialColors = false; foreach (var materialCount in sizeOption.MaterialCounts) { var materialColorCosts = materialCount.Material.Colors.Select(c => c.Cost); if (materialColorCosts.Count() == 0) { continue; } hasMaterialColors = true; minMaterialCost.Add(new Tuple <decimal, decimal>(materialCount.MaterialUnitCount, materialColorCosts.Min())); maxMaterialCost.Add(new Tuple <decimal, decimal>(materialCount.MaterialUnitCount, materialColorCosts.Max())); avgMaterialCost.Add(new Tuple <decimal, decimal>(materialCount.MaterialUnitCount, materialColorCosts.Average())); } if (!hasMaterialColors) { continue; } var anserv = new AnalysisService(); var highestProfit = anserv.CalculateProfit(sizeOption, minMaterialCost); var lowestProfit = anserv.CalculateProfit(sizeOption, maxMaterialCost); var averageProfit = anserv.CalculateProfit(sizeOption, avgMaterialCost); Console.WriteLine($"\t\tMinimum Profit: {CommonClientFunctions.ConvertToMoney(lowestProfit)} - " + $"Minimum Profit Per Hour: {CommonClientFunctions.ConvertToMoney(anserv.ValuePerHour(sizeOption.TimeToMakeInHours, lowestProfit))}"); Console.WriteLine($"\t\tMaximum Profit: {CommonClientFunctions.ConvertToMoney(highestProfit)} - " + $"Maximum Profit Per Hour: {CommonClientFunctions.ConvertToMoney(anserv.ValuePerHour(sizeOption.TimeToMakeInHours, highestProfit))}"); Console.WriteLine($"\t\tAverage Profit: {CommonClientFunctions.ConvertToMoney(averageProfit)} - " + $"Average Profit Per Hour: {CommonClientFunctions.ConvertToMoney(anserv.ValuePerHour(sizeOption.TimeToMakeInHours, averageProfit))}"); } } }
private void UpdateItem() { Console.WriteLine("Pick an Item to Edit"); var items = CommonClientFunctions.ReadItems(); var hasElements = CommonClientFunctions.EntitySelection(items, out Item item); if (!hasElements) { Console.WriteLine("No Items Available"); return; } if (item is null) { return; } Console.Write($"Name ({item.Name})> "); var newName = Console.ReadLine(); Console.Write($"Name ({item.Description})> "); var newDescription = Console.ReadLine(); item.Name = String.IsNullOrWhiteSpace(newName) ? item.Name : newName; item.Description = String.IsNullOrWhiteSpace(newDescription) ? item.Description : newDescription; using (var db = new ShopContext()) { new DataService(db).Update(item); } CommonClientFunctions.Menuing(MenuOptionsUpdateItemSizeOption(), (actionInput) => { switch (actionInput) { case 1: CreateSizeOption(item); break; case 2: UpdateSizeOption(item); break; case 3: DeleteSizeOption(item); break; } }); }
private void UpdateMaterials() { Console.WriteLine("Pick a Material to Edit"); var materials = CommonClientFunctions.ReadMaterials(); var hasElements = CommonClientFunctions.EntitySelection(materials, out Material material); if (!hasElements) { Console.WriteLine("No Materials Available"); return; } if (material is null) { return; } Console.Write($"Name ({material.FullMaterialName})> "); var newFullMaterialName = Console.ReadLine(); Console.Write($"Name ({material.FriendlyName})> "); var newFriendlyName = Console.ReadLine(); material.FullMaterialName = String.IsNullOrWhiteSpace(newFullMaterialName) ? material.FullMaterialName : newFullMaterialName; material.FriendlyName = String.IsNullOrWhiteSpace(newFriendlyName) ? material.FriendlyName : newFriendlyName; using (var db = new ShopContext()) { new DataService(db).Update(material); } CommonClientFunctions.Menuing(MenuOptionsUpdateMaterials(), (actionInput) => { switch (actionInput) { case 1: CreateColor(material); break; case 2: UpdateColors(material); break; case 3: DeleteColor(material); break; } }); }
private void CreateItem() { List <Material> materials = CommonClientFunctions.ReadMaterials(); if (materials.Count == 0) { Console.WriteLine("There must be materials created prior to making an item"); return; } Console.Write("Enter Item Name> "); string name = Console.ReadLine(); Console.Write("Enter Item Description> "); string description = Console.ReadLine(); List <SizeOption> sizeOptions = new List <SizeOption>(); Console.WriteLine("Enter Sizing Information."); do { var sizeOption = CreateSizeOption(materials); if (sizeOption is null) { return; } sizeOptions.Add(sizeOption); Console.Write("Enter another sizing option? (\"yes\" or \"no\")> "); string cont = Console.ReadLine(); if (!cont.ToLowerInvariant().Equals("yes")) { break; } } while (true); Item newItem = new Item() { Name = name, Description = description, SizeOptions = sizeOptions }; using (var db = new ShopContext()) { new DataService(db).Create(newItem); } }
private void CreateMaterialCount(SizeOption option) { List <Material> materials = CommonClientFunctions.ReadMaterials(); var materialCount = CreateMaterialCount(materials); if (materialCount is null) { return; } materialCount.SizeOptionId = option.Id; option.MaterialCounts.Add(materialCount); using var db = new ShopContext(); new DataService(db).Create(materialCount); }
private void DeleteColor(Material material) { var colors = CommonClientFunctions.ReadColorsByMaterialId(material.Id); var hasElements = CommonClientFunctions.EntitySelection(colors, out Color color, 1); if (!hasElements) { Console.WriteLine("No Colors Available"); return; } if (color is null) { return; } using (var db = new ShopContext()) { new DataService(db).Delete(color); } }
private void DeleteMaterialCount(SizeOption option) { var materialCounts = CommonClientFunctions.ReadMaterialCountsBySizeOptionId(option.Id); var hasElements = CommonClientFunctions.EntitySelection(materialCounts, out MaterialCount materialCount, 1); if (!hasElements) { Console.WriteLine("No Material Counts Available"); return; } if (materialCount is null) { return; } using (var db = new ShopContext()) { new DataService(db).Delete(materialCount); } }
private void DeleteSizeOption(Item item) { var options = CommonClientFunctions.ReadSizeOptionsByItemId(item.Id); var hasElements = CommonClientFunctions.EntitySelection(options, out SizeOption option, 1); if (!hasElements) { Console.WriteLine("No Size Options Available"); return; } if (option is null) { return; } using (var db = new ShopContext()) { new DataService(db).Delete(option); } }
private void DeleteMaterial() { Console.WriteLine("Pick a Material to Delete"); var materials = CommonClientFunctions.ReadMaterials(); var hasElements = CommonClientFunctions.EntitySelection(materials, out Material material); if (!hasElements) { Console.WriteLine("No Materials Available"); return; } if (material is null) { return; } using (var db = new ShopContext()) { new DataService(db).Delete(material); } }
private void UpdateColors(Material material) { var colors = material.Colors; var hasElements = CommonClientFunctions.EntitySelection(colors, out Color color, 1); if (!hasElements) { Console.WriteLine("No Colors Available"); return; } if (color is null) { return; } Console.Write($"Name ({color.Name})> "); var newColorName = Console.ReadLine(); Console.Write($"Color Code ({color.ColorCode})> "); var newColorCode = Console.ReadLine(); Console.Write($"Cost ({color.Cost})> "); var pInput = Console.ReadLine(); if (String.IsNullOrWhiteSpace(pInput)) { pInput = "-1"; } Int32.TryParse(pInput, out int newCost); color.Name = String.IsNullOrWhiteSpace(newColorName) ? color.Name : newColorName; color.ColorCode = String.IsNullOrWhiteSpace(newColorCode) ? color.ColorCode : newColorCode; color.Cost = newCost == -1 ? color.Cost : newCost; using (var db = new ShopContext()) { new DataService(db).Update(color); } }
private void DeleteItem() { Console.WriteLine("Pick an Item to Delete"); var items = CommonClientFunctions.ReadItems(); var hasElements = CommonClientFunctions.EntitySelection(items, out Item item); if (!hasElements) { Console.WriteLine("No Items Available"); return; } if (item is null) { return; } using (var db = new ShopContext()) { new DataService(db).Delete(item); } }
public void Run() { CommonClientFunctions.Menuing(MenuOptionsItem(), (actionInput) => { switch (actionInput) { case 1: CreateItem(); break; case 2: CommonClientFunctions.ListItems(); break; case 3: UpdateItem(); break; case 4: DeleteItem(); break; } }); }
private void EditMaterialCount(SizeOption option) { var materialCounts = option.MaterialCounts; var hasElements = CommonClientFunctions.EntitySelection(materialCounts, out MaterialCount materialCount, 1); if (!hasElements) { Console.WriteLine("No Material Counts Available"); return; } if (materialCount is null) { return; } Console.Write($"Description ({materialCount.Description})> "); string newDescription = Console.ReadLine(); Console.Write($"Count ({materialCount.MaterialUnitCount})> "); var pInput = Console.ReadLine(); if (String.IsNullOrWhiteSpace(pInput)) { pInput = "-1"; } Decimal.TryParse(pInput, out decimal newCount); materialCount.MaterialUnitCount = newCount == -1 ? materialCount.MaterialUnitCount : newCount; materialCount.Description = String.IsNullOrWhiteSpace(newDescription) ? materialCount.Description : newDescription; using (var db = new ShopContext()) { new DataService(db).Update(materialCount); } }
public void UpdateSizeOption(Item item) { var options = item.SizeOptions; var hasElements = CommonClientFunctions.EntitySelection(options, out SizeOption option, 1); if (!hasElements) { Console.WriteLine("No Size Options Available"); return; } if (option is null) { return; } Console.Write($"Size ({option.Size})> "); var newSize = Console.ReadLine(); decimal newPrice; string priceInput; do { newPrice = -1; Console.Write($"Price ({option.Price})> "); priceInput = Console.ReadLine().Replace("$", ""); if (String.IsNullOrWhiteSpace(priceInput)) { break; } Decimal.TryParse(priceInput, out newPrice); } while (newPrice <= 0); int newTTM; string timeInput; do { newTTM = -1; Console.Write($"Time To Make In Hours. Must be Non Zero. ({option.TimeToMakeInHours})> "); timeInput = Console.ReadLine(); if (String.IsNullOrWhiteSpace(timeInput)) { break; } Int32.TryParse(timeInput, out newTTM); } while (newTTM <= 0); option.Size = String.IsNullOrWhiteSpace(newSize) ? option.Size : newSize; option.Price = newPrice == -1 ? option.Price : newPrice; option.TimeToMakeInHours = newTTM == -1 ? option.TimeToMakeInHours : newTTM; using (var db = new ShopContext()) { new DataService(db).Update(option); } CommonClientFunctions.Menuing(MenuOptionsUpdateSizeOptionMaterialCount(), (actionInput) => { switch (actionInput) { case 1: CreateMaterialCount(option); break; case 2: EditMaterialCount(option); break; case 3: DeleteMaterialCount(option); break; } }); }