Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void Auth(UserCardAuthDto dto)
        {
            if (dto.User == null || dto.Card == null)
            {
                return;
            }

            AddOrUpdateUser(dto.User);
            dto.Card.User = dto.User.PkId;
            AddOrUpdateCard(dto.Card);
            UpdateAuth(dto.Card.PkId, dto.Devices);

            dbCtx.SaveChanges();
        }
Esempio n. 4
0
        private int SubmitAuth(UserCardAuthDto dto)
        {
            //写卡
            var writeResult = 0;
            var reader      = Reader.Singleton;

            if (reader.Connect())
            {
                //第三扇区
                writeResult = reader.WriteCard(2, dto.GetAuthStr());
                reader.DisConnect();
            }
            if (writeResult == 1)
            {
                new UserCardAuth().Auth(dto);
            }
            return(writeResult);
        }