/// <summary> /// 获得饲料类型下拉列表 /// </summary> /// <returns>返回集合</returns> public IEnumerable<SelectListItem> GetFodderTypeList() { var fodderTypeSelect = new FodderTypeService(); IEnumerable<SelectListItem> fodderTypeSelectList = fodderTypeSelect.FindAll().Select(fodderItem => new SelectListItem { Text = fodderItem.Name, Value = fodderItem.Id + string.Empty }).OrderBy(m => m.Text); return fodderTypeSelectList; }
public void FodderTypeSaveChanges(BasicInfoModel model) { var fodderTypeService = new FodderTypeService(); List<fodder_type> fodderTypes = fodderTypeService.FindAll(); foreach (fodder_type fodderType in fodderTypes) { int idFlag = 0; int nameFlag = 0; string newname = ""; foreach (NameModel name in model.Names) { if (fodderType.Id == name.Id) { idFlag = 1; if (fodderType.Name.Equals(name.Name)) { nameFlag = 1; } else { newname = name.Name; } } } //若存在此Id,但是name变化了的,则需要修改数据库 if (idFlag == 1) { if (nameFlag == 0) { if (newname == "") { throw new Exception(); } fodder_type modifyCure = fodderTypeService.Find(fodderType.Id); modifyCure.Name = newname; fodderTypeService.Update(modifyCure); } } } //如果model里的Id为0,说明是新建的类型 foreach (NameModel name in model.Names) { if (name.Id == 0 && fodderTypeService.FindByName(name.Name) == null) { var newType = new fodder_type {Name = name.Name}; fodderTypeService.Insert(newType); } } }