/// <summary> /// 获得单位下拉列表 /// </summary> /// <returns>返回集合</returns> public IEnumerable<SelectListItem> GetUnitList() { var unitSelect = new UnitService(); IEnumerable<SelectListItem> unitSelectList = unitSelect.FindAll().Select(unitItem => new SelectListItem { Text = unitItem.Name, Value = unitItem.Id + string.Empty }).OrderBy(m => m.Text); return unitSelectList; }
public void UnitTypeSaveChanges(BasicInfoModel model) { var unitTypeService = new UnitService(); List<unit> unitTypes = unitTypeService.FindAll(); foreach (unit unitType in unitTypes) { int idFlag = 0; int nameFlag = 0; string newname = ""; foreach (NameModel name in model.Names) { if (unitType.Id == name.Id) { idFlag = 1; if (unitType.Name.Equals(name.Name)) { nameFlag = 1; } else { newname = name.Name; } } } //若存在此Id,但是name变化了的,则需要修改数据库 if (idFlag == 1) { if (nameFlag == 0) { if (newname == "") { throw new Exception(); } unit modifyCure = unitTypeService.Find(unitType.Id); modifyCure.Name = newname; unitTypeService.Update(modifyCure); } } } //如果model里的Id为0,说明是新建的类型 foreach (NameModel name in model.Names) { if (name.Id == 0 && unitTypeService.FindByName(name.Name) == null) { var newUnitType = new unit {Name = name.Name}; new UnitService().Insert(newUnitType); } } }