コード例 #1
0
 /// <summary>
 ///     获得猪类型下拉列表
 /// </summary>
 /// <returns>返回集合</returns>
 public IEnumerable<SelectListItem> GetPigTypeList()
 {
     var pigTypeService = new PigTypeService();
     IEnumerable<SelectListItem> pigTypeList =
         pigTypeService.FindAll().Select(pigTypeItem => new SelectListItem
                                                            {
                                                                Text = pigTypeItem.Name,
                                                                Value = pigTypeItem.Id + string.Empty,
                                                            }).OrderBy(m => m.Text);
     return pigTypeList;
 }
コード例 #2
0
ファイル: NameModel.cs プロジェクト: dalinhuang/2010graduate
 public void PigTypeSaveChanges(BasicInfoModel model)
 {
     var typeService = new PigTypeService();
     List<pig_type> types = typeService.FindAll();
     foreach (pig_type type in types)
     {
         int idFlag = 0;
         int nameFlag = 0;
         string newname = "";
         foreach (NameModel name in model.Names)
         {
             if (type.Id == name.Id)
             {
                 idFlag = 1;
                 if (type.Name.Equals(name.Name))
                 {
                     nameFlag = 1;
                 }
                 else
                 {
                     newname = name.Name;
                 }
             }
         }
         //若存在此Id,但是name变化了的,则需要修改数据库
         if (idFlag == 1)
         {
             if (nameFlag == 0)
             {
                 if (newname == "")
                 {
                     throw new Exception();
                 }
                 pig_type modifyCure = typeService.Find(type.Id);
                 modifyCure.Name = newname;
                 typeService.Update(modifyCure);
             }
         }
     }
     //如果model里的Id为0,说明是新建的类型
     foreach (NameModel name in model.Names)
     {
         if (name.Id == 0 && typeService.FindByName(name.Name) == null)
         {
             var newType = new pig_type {Name = name.Name};
             typeService.Insert(newType);
         }
     }
 }