// GET: StockManagement public ActionResult Index() { var stocks = _stockManagementService.GetStocks(); var model = GetGridModel(stocks); return(View(model)); }
private GridViewModel <ResourceModel> GetGridModel(IEnumerable <ResourceModel> resources) { var model = new GridViewModel <ResourceModel>(resources, "Id"); var stocks = _stockManagementService.GetStocks(); var stocksId = new HashSet <int>(resources.Select(r => r.StockId).ToList()); List <string> stocksWithResourcesNames = new List <string>(); foreach (var id in stocksId) { stocksWithResourcesNames.Add(stocks.Where(s => s.Id == id).Select(s => s.Name).FirstOrDefault()); } var columns = new List <GridColumnViewModel> { new GridColumnViewModel("Id", ControlType.Hidden), new GridColumnViewModel("StockId", ControlType.Select, new SelectList(stocks, "Id", "Name"), true, columnValues: stocksWithResourcesNames.OrderBy(s => s)), new GridColumnViewModel("Name", ControlType.Input, isEditable: true, columnValues: resources.Select(n => n.Name).OrderBy(n => n)), new GridColumnViewModel("PriceBase", ControlType.Input), new GridColumnViewModel("Price", ControlType.Input) }; model.Columns = columns; return(model); }
public IActionResult Index() { var stocks = _stockManagementService.GetStocks(); var tableModel = GetTableModel(stocks, null); var model = new ManagementTableViewModel(tableModel, nameof(CreateStock), nameof(EditStock), nameof(DeleteStock)); return(View("TableEditor/_Table", model)); }
private TableEditorModel GetTableModel(IEnumerable <CurrencyManagementModel> currencies, CurrencyManagementModel currency) { var entityType = typeof(CurrencyManagementModel); var tableModel = new TableEditorModel("Currencies", entityType, "Id", currencies, currency); var stocks = _stockManagementService.GetStocks().OrderBy(s => s.Name); _tableEditorService.AddColumn(tableModel, "Id", null); _tableEditorService.AddColumn(tableModel, "Name", null, ControlType.Input, null); _tableEditorService.AddColumn(tableModel, "StockId", null, ControlType.Select, new SelectList(stocks, "Id", "Name")); return(tableModel); }
private GridViewModel <CurrencyModel> GetGridViewModel(IEnumerable <CurrencyModel> money) { var model = new GridViewModel <CurrencyModel>(money); var stocks = _stockManagementService.GetStocks(); var columns = new List <GridColumnViewModel> { new GridColumnViewModel("Id"), new GridColumnViewModel("StockId", ControlType.Select, new SelectList(stocks, "Id", "Name")), new GridColumnViewModel("Name"), new GridColumnViewModel("BuyPrice"), new GridColumnViewModel("SellPrice") }; model.Columns = columns; return(model); }