public ResultObj Update(InspectCycles newObj) { ResultObj resultObj = new ResultObj(); var obj = _context.InspectCycles.Find(newObj.GId); if (obj == null) { resultObj.IsSuccess = false; resultObj.ErrMsg = "修改对象不存在。"; return(resultObj); } if (IsExistSameName(newObj)) { resultObj.IsSuccess = false; resultObj.ErrMsg = "名称已存在。"; return(resultObj); } obj.CycleName = newObj.CycleName; obj.CycleType = newObj.CycleType; obj.Remark = newObj.Remark; obj.LastUpdateTime = DateTime.Now; obj.LastUpdateUser = newObj.LastUpdateUser; _context.InspectCycles.Update(obj); _context.SaveChanges(); resultObj.IsSuccess = true; return(resultObj); }
public bool IsExistSameName(InspectCycles obj) { var where = _context.InspectCycles.Where(p => p.CycleName == obj.CycleName); if (obj.GId != null) { where = where.Where(p => p.GId != obj.GId); } List <InspectCycles> list = where.ToList(); if (list.Count > 0) { return(true); } return(false); }
public ResultObj Add(InspectCycles obj) { ResultObj resultObj = new ResultObj(); if (IsExistSameName(obj)) { resultObj.IsSuccess = false; resultObj.ErrMsg = "名称已存在。"; return(resultObj); } obj.CreateUser = obj.CreateUser; obj.CreateTime = DateTime.Now; obj.LastUpdateUser = obj.LastUpdateUser; obj.LastUpdateTime = DateTime.Now; _context.InspectCycles.Add(obj); _context.SaveChanges(); resultObj.IsSuccess = true; return(resultObj); }