做添加或修改时判断用户名name是否存在

来源:互联网 发布:谷歌怎么安装js插件 编辑:程序博客网 时间:2024/05/23 16:55

当name可以修改的时候

      public bool IsExistTankCodeByInputCode(long? tankId, string inputCode)        {            bool isExist = true;            int count = 0;            if (string.IsNullOrEmpty(tankId.ToString()))//add            {                count = GetTankModelList().Where(e => e.Code == inputCode).ToList().Count;                if (count == 0) isExist = false;            }            else//edit            {                if (GetTankModelByTankId(tankId.Value).Code == inputCode)//original code                {                    isExist = false;                }                else                {                    count = GetTankModelList().Where(e => e.Code == inputCode).ToList().Count;                    if (count == 0) isExist = false;                }            }            return isExist;        }

当name不需要修改的时候

 public bool IsExistTankNameByInputName(long tankId, string inputName){     #region when name is not edit            if (id == 0)//add            {               count = GetTankList().Where(e => e.Name == name).ToList().Count;             if (count == 0) isExist = false;            }            else//edit            {                count = GetTankList().Where(e => e.TankID == id && e.Name == name).ToList().Count;               if (count == 1) isExist = false;            }            #endregion   return isExist;}


注解:

GetTankModelList()与GetTankList()都是一个list集合

GetTankModelByTankId根据id取得list集合