public UserCardAuthDto GetByCardIdOrUserId(string cardId, string userId) { var dto = new UserCardAuthDto(); if (!string.IsNullOrEmpty(cardId)) { dto.Card = new BaseRepo <CardInfo>(dbCtx).Find(cardId); if (dto.Card != null) { dto.User = new BaseRepo <UserInfo>(dbCtx).Find(dto.Card.User); var deviceIds = new BaseRepo <CardAuth>(dbCtx) .Find(t => t.Card == dto.Card.PkId) .Select(t => t.Device) .ToArray(); dto.Devices = new BaseRepo <Device>(dbCtx) .Find(t => deviceIds.Contains(t.PkId)) .ToList(); } } else if (!string.IsNullOrEmpty(userId)) { dto.User = new BaseRepo <UserInfo>(dbCtx).Find(userId); } return(dto); }
public UserCardAuthDto GetByCardNo(string cardNo) { var dto = new UserCardAuthDto(); dto.Card = new BaseRepo <CardInfo>(dbCtx) .Find(t => t.CardNo == cardNo).FirstOrDefault(); if (dto.Card == null) { dto.Card = new CardInfo() { CardNo = cardNo }; } else { dto.User = new BaseRepo <UserInfo>(dbCtx).Find(dto.Card.User); var deviceIds = new BaseRepo <CardAuth>(dbCtx) .Find(t => t.Card == dto.Card.PkId) .Select(t => t.Device) .ToArray(); dto.Devices = new BaseRepo <Device>(dbCtx) .Find(t => deviceIds.Contains(t.PkId)) .ToList(); } return(dto); }