// GET: Products/Details/5 public async Task <ActionResult> Details(int id) { var categories = await _categoryManager.GetAll(); var manufacturers = await _manufacturerManager.GetAll(); var characteristics = await _characteristicManager.GetAll(); var product = await _productManager.GetById(id); var productViewModel = MapProduct(product, categories, manufacturers); productViewModel.Fields = MapFields(product, characteristics); return(View(productViewModel)); }
private async Task PrintProductDetails() { var productDto = await _productManager.GetById(ProductId); var productViewModel = new ProductViewModel { Amount = productDto.AmountInStorage, Fields = productDto.Fields, Manufacturer = (await _manufacturerManager.GetById(productDto.ManufacturerId)).Name, Name = productDto.Name, Price = productDto.Price }; Console.Write("Product name: "); Console.WriteLine(productViewModel.Name); Console.Write("Price: "); Console.WriteLine(productViewModel.Price); Console.Write("Amount: "); Console.WriteLine(productViewModel.Amount); Console.Write("Manufacturer: "); Console.WriteLine(productViewModel.Manufacturer); var characteristics = await _characteristicManager.GetAll(); productViewModel.Fields.ToList() .ForEach(field => { Console.Write(characteristics.First(characteristic => characteristic.Id == field.CharacteristicId).Name); Console.Write(":"); Console.Write(field.Value); Console.WriteLine(); }); }
// GET: Characteristics public async Task <ActionResult> Index() { var categories = await _categoryManager.GetAll(); var characteristicViewModels = (await _characteristicManager.GetAll()) .Select(characteristic => MapCharacteristic(characteristic, categories)) .OrderBy(characteristic => characteristic.CategoryName); return(View(characteristicViewModels)); }
public async Task <Product> CreateModel() { Console.WriteLine("Enter name of product"); var name = Console.ReadLine(); Console.WriteLine("Enter price of product"); var price = decimal.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); Console.WriteLine("Enter amount of product"); var amount = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); (await _manufacturerManager.GetAll()).WriteCollectionAsTable(); Console.WriteLine("Enter Id of manufacturer"); var manufacturerId = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); (await _categoryManager.GetAll()).WriteCollectionAsTable(); Console.WriteLine("Enter Id of category"); var categoryId = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); var productDto = new Product { Name = name, Price = price, ManufacturerId = manufacturerId, CategoryId = categoryId, AmountInStorage = amount }; var productCharacteristics = (await _characteristicManager.GetAll()) .Where(characteristicDto => characteristicDto.CategoryId == productDto.CategoryId) .ToList(); var fieldList = new List <Field>(); productCharacteristics.ForEach(characteristic => { Console.WriteLine($"Enter value of characteristic {characteristic.Name}"); var value = Console.ReadLine(); fieldList.Add(new Field { CharacteristicId = characteristic.Id, Value = value }); }); productDto.Fields = fieldList; return(productDto); }
public async Task PrintAll() { var categories = await _categoryManager.GetAll(); var items = (await _characteristicManager.GetAll()).Select(item => new CharacteristicViewModel { CharacteristicId = item.Id, CategoryId = item.CategoryId, CategoryName = categories .First(category => category.Id == item.CategoryId) .Name, CharacteristicName = item.Name }); items.WriteCollectionAsTable(); }
public async Task <ActionResult <IEnumerable <Characteristic> > > Get() { var characteristics = (await _characteristicManager.GetAll()).ToList(); return(characteristics); }