public static SelectList GetSelectList_Warehouse(object sValue, string NullOrNameEmpty) { var selectListItems = new List <SelectListItem>(); WarehouseRepository warehouseRepository = new WarehouseRepository(new Domain.Sale.ErpSaleDbContext()); if (NullOrNameEmpty != null) { SelectListItem itemEmpty = new SelectListItem(); itemEmpty.Text = NullOrNameEmpty; itemEmpty.Value = null; selectListItems.Add(itemEmpty); } try { var q = warehouseRepository.GetAllWarehouse().OrderBy(item => item.Id); foreach (var i in q) { SelectListItem item = new SelectListItem(); item.Text = i.Name; item.Value = i.Id.ToString(); selectListItems.Add(item); } } catch { } var selectList = new SelectList(selectListItems, "Value", "Text", sValue); return(selectList); }
public static SelectList GetSelectList_Warehouse(object sValue, int?BranchId, string NullOrNameEmpty, bool IsSale = true) { var selectListItems = new List <SelectListItem>(); WarehouseRepository warehouseRepository = new WarehouseRepository(new Domain.Sale.ErpSaleDbContext()); if (NullOrNameEmpty != null) { SelectListItem itemEmpty = new SelectListItem(); itemEmpty.Text = NullOrNameEmpty; itemEmpty.Value = null; selectListItems.Add(itemEmpty); } try { var q = warehouseRepository.GetAllWarehouse().Where(x => x.IsSale == IsSale).OrderBy(item => item.Id).AsEnumerable(); if (BranchId != null) { q = q.Where(x => x.BranchId == BranchId); } foreach (var i in q) { SelectListItem item = new SelectListItem(); item.Text = i.Name; item.Value = i.Id.ToString(); selectListItems.Add(item); } } catch { } var selectList = new SelectList(selectListItems, "Value", "Text", sValue); return(selectList); }