コード例 #1
0
ファイル: CardService.cs プロジェクト: dahaideyu/api
        /// <summary>
        /// 卡转码(临时用)
        /// </summary>
        public void InsertCardNoConvert()
        {
            var query = _cardRepository.Table;

            try
            {
                _unitOfWork.BeginTransaction();

                var convertList = new List <CardNoConvertEntity>();

                foreach (var item in query.ToList())
                {
                    foreach (var type in Constant.ConvertTypeList)
                    {
                        var convertDto = new CardNoConvertEntity
                        {
                            CardNOConverUUID = Guid.NewGuid().ToString("N"),
                            CardUUID         = item.CardUUID,
                            CardConvertType  = type,
                            CardConvertNo    = CardNoConvert.ConvertCardNo(item.CardNo, type, item.CardType)
                        };
                        convertList.Add(convertDto);
                    }
                }
                if (convertList != null && convertList.Count > 0)
                {
                    _convertRepository.Insert(convertList);
                }

                _unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                Log.Error(null, ex.Message);
                _unitOfWork.Rollback();
            }
        }
コード例 #2
0
ファイル: CardService.cs プロジェクト: dahaideyu/api
        //public IList<CardListDto> GetCardListByRoomUserID(string roomUserId)
        //{
        //    var query = from c in _cardRepository.Table
        //                join uc in _userCardRepository.Table on c.CardUUID equals uc.CardUUID
        //                where uc.RoomUserUUID == roomUserId
        //                orderby c.CreateTime descending
        //                select c;

        //    var cardList = new List<CardListDto>();

        //    foreach (var item in query.ToList())
        //    {
        //        var model = new CardListDto();
        //        model.CardUUID = item.CardUUID;
        //        model.CardNo = item.CardNo;
        //        model.CardType = item.CardType;
        //        model.CardTypeName = item.CardTypeDict != null ? item.CardTypeDict.DictName : "";
        //        model.CreateTime = DateTime.Now;
        //        cardList.Add(model);
        //    }

        //    return cardList;
        //}


        /// <summary>
        /// 办卡,存入卡信息,生成用户和卡的关联
        /// </summary>
        /// <param name="model"></param>
        public virtual void Create(CardDto model)
        {
            var result = false;

            try
            {
                _unitOfWork.BeginTransaction();

                var entity = model.MapTo <CardEntity>();
                entity.CreateTime  = DateTime.Now;
                entity.UpdateTime  = entity.CreateTime;
                entity.CardLast4NO = entity.CardNo.Substring(entity.CardNo.Length - 4, 4);
                entity.Deleted     = false;
                entity.SyncStatus  = false;
                entity.SyncVersion = 0;
                _cardRepository.Insert(entity);


                var convertList = new List <CardNoConvertEntity>();

                foreach (var type in Constant.ConvertTypeList)
                {
                    var convertDto = new CardNoConvertEntity
                    {
                        CardNOConverUUID = Guid.NewGuid().ToString("N"),
                        CardUUID         = model.CardUUID,
                        CardConvertType  = type,
                        CardConvertNo    = CardNoConvert.ConvertCardNo(model.CardNo, type, model.CardType)
                    };
                    convertList.Add(convertDto);
                }


                if (convertList != null && convertList.Count > 0)
                {
                    _convertRepository.Insert(convertList);
                }

                RoomUserCardEntity userCardEntity = null;

                if (model.IsManage)
                {
                    var manageCard = new ManageCardEntity()
                    {
                        Guid       = Guid.NewGuid().ToString("N"),
                        PersonUUID = model.PersonUUID,
                        CardUUID   = entity.CardUUID
                    };
                    _manageCardRepository.Insert(manageCard);
                }
                else
                {
                    userCardEntity = new RoomUserCardEntity();
                    userCardEntity.RoomUserCardUUID = Guid.NewGuid().ToString("N");
                    userCardEntity.RoomUserUUID     = model.RoomUserUUID;
                    userCardEntity.CardUUID         = entity.CardUUID;
                    userCardEntity.CreateTime       = entity.CreateTime;
                    userCardEntity.UpdateTime       = entity.UpdateTime;
                    userCardEntity.Deleted          = false;
                    userCardEntity.SyncStatus       = false;
                    userCardEntity.SyncVersion      = 0;
                    _userCardRepository.Insert(userCardEntity);
                }


                _unitOfWork.Commit();

                result = true;


                if (result)
                {
                    SynchronizationCard(entity.CardUUID);
                    SynchronizationPersonCard(entity.CardUUID);
                }
            }
            catch (Exception ex)
            {
                Log.Error(null, ex.Message);
                _unitOfWork.Rollback();
            }
        }