示例#1
0
 public void ExceptionTypeSaveChanges(BasicInfoModel model)
 {
     var exceptionTypeService = new ExceptionTypeService();
     List<exception_type> exceptionTypes = exceptionTypeService.FindAll();
     foreach (exception_type exceptionType in exceptionTypes)
     {
         int idFlag = 0;
         int nameFlag = 0;
         string newname = "";
         foreach (NameModel name in model.Names)
         {
             if (exceptionType.Id == name.Id)
             {
                 idFlag = 1;
                 if (exceptionType.Name.Equals(name.Name))
                 {
                     nameFlag = 1;
                 }
                 else
                 {
                     newname = name.Name;
                 }
             }
         }
         //若存在此Id,但是name变化了的,则需要修改数据库
         if (idFlag == 1)
         {
             if (nameFlag == 0)
             {
                 if (newname == "")
                 {
                     throw new Exception();
                 }
                 exception_type modifyCure = exceptionTypeService.Find(exceptionType.Id);
                 modifyCure.Name = newname;
                 exceptionTypeService.Update(modifyCure);
             }
         }
     }
     //如果model里的Id为0,说明是新建的类型
     foreach (NameModel name in model.Names)
     {
         if (name.Id == 0 && exceptionTypeService.FindByName(name.Name).Count == 0)
         {
             var newExcpetionType = new exception_type {Name = name.Name};
             exceptionTypeService.Insert(newExcpetionType);
         }
     }
 }