Exemple #1
0
 public void TaskTypeSaveChanges(BasicInfoModel model)
 {
     var typeService = new TaskTypeService();
     List<task_type> types = typeService.FindAll();
     foreach (task_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();
                 }
                 task_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 task_type {Name = name.Name};
             typeService.Insert(newType);
         }
     }
 }