예제 #1
0
 /// <summary>
 ///     巡查异常下拉列表
 /// </summary>
 /// <returns></returns>
 public IEnumerable<SelectListItem> GetExceptionTypeList()
 {
     var exceptionService = new ExceptionTypeService();
     IEnumerable<SelectListItem> pigTypeList =
         exceptionService.FindAll().Select(exceptionItem => new SelectListItem
                                                                {
                                                                    Text = exceptionItem.Name,
                                                                    Value = exceptionItem.Id + string.Empty,
                                                                }).OrderBy(m => m.Text);
     return pigTypeList;
 }
예제 #2
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);
         }
     }
 }