Example #1
0
        public static SelectList GetSelectList_CarLine(string manufacturerCar, object SelectedValue, string NullOrNameEmpty)
        {
            ICarLineService carLineService  = DependencyResolver.Current.GetService <ICarLineService>();
            var             selectListItems = new List <SelectListItem>();

            if (NullOrNameEmpty != null)
            {
                SelectListItem itemEmpty = new SelectListItem();
                itemEmpty.Text  = NullOrNameEmpty;
                itemEmpty.Value = null;
                selectListItems.Add(itemEmpty);
            }

            try
            {
                var db = carLineService.GetByManufacturerCar(manufacturerCar).ToList();
                foreach (var i in db)
                {
                    SelectListItem item = new SelectListItem();
                    item.Text  = i.Name;
                    item.Value = i.Id.ToString();
                    selectListItems.Add(item);
                }
            }
            catch { }

            var selectList = new SelectList(selectListItems, "Value", "Text", SelectedValue);

            return(selectList);
        }
        public object FetchCarLines(string manufacturerCar)
        {
            var db = CarLineService.GetByManufacturerCar(manufacturerCar).ToList();

            db.Insert(0, new CarLine()
            {
                Id = -1, Name = "- Dòng xe -"
            });
            return(db.Select(n => new { n.Id, n.Name }));
        }