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