コード例 #1
0
        private IMS_Associate CreateAssociate(IMS_InviteCodeRequest request)
        {
            using (var db = new YintaiHZhouContext())
            {
                var section =
                    db.Set <Section>()
                    .FirstOrDefault(x => x.SectionCode == request.SectionCode && x.StoreId == request.StoreId);
                if (section == null)
                {
                    return(null);
                }

                var associate = new IMS_Associate()
                {
                    CreateDate   = DateTime.Now,
                    CreateUser   = request.UserId,
                    OperateRight = request.RequestType == 2 ? 7 : 3,
                    SectionId    = section.Id,
                    Status       = 1,
                    StoreId      = request.StoreId,
                    UserId       = request.UserId,
                    TemplateId   = int.Parse(ConfigurationManager.AppSettings["IMS_Default_Template"]),
                    OperatorCode = request.OperatorCode,
                };

                associate = db.Set <IMS_Associate>().Add(associate);
                db.SaveChanges();
                return(associate);
            }
        }
コード例 #2
0
        /// <summary>
        /// 开店初始化
        /// </summary>
        /// <param name="context"></param>
        /// <param name="entity"></param>
        /// <param name="currentUserId"></param>
        private void InitializeAssociateTables(DbContext context, IMS_InviteCodeRequest entity, int currentUserId)
        {
            //steps:
            // 1. read initial info from invite code tables
            // 2. initialize associate tables

            //var initialBrands = Context.Set<IMS_SectionBrand>().Where(isb => isb.SectionId == inviteEntity.Sec.SectionId);
            //var initialSaleCodes = Context.Set<IMS_SalesCode>().Where(isc => isc.SectionId == inviteEntity.Sec.SectionId);
            var users         = context.Set <User>();
            var sections      = context.Set <Section>();
            var imsAssociate  = context.Set <IMS_Associate>();
            var sectionbrands = context.Set <IMS_SectionBrand>();
            var salescodes    = context.Set <IMS_SalesCode>();
            var giftcards     = context.Set <IMS_GiftCard>();

            //1验证
            var exitUserEntity = users.FirstOrDefault(v => v.Id == entity.UserId);

            if (exitUserEntity == null)
            {
                throw new OpcException(String.Format("申请单{0}用户{1}未找到", entity.Id, entity.UserId));
            }

            var section =
                sections.FirstOrDefault(v => v.StoreId == entity.StoreId && v.SectionCode == entity.SectionCode);

            if (section == null)
            {
                throw new OpcException(String.Format("申请单{0}门店{1}专柜码{2}专柜未找到", entity.Id, entity.StoreId, entity.SectionCode));
            }

            var requestType  = (InviteCodeRequestType)entity.RequestType;
            var operateRight = requestType == InviteCodeRequestType.Daogou
                ? (UserOperatorRight.GiftCard | UserOperatorRight.SelfProduct | UserOperatorRight.SystemProduct)
                : (UserOperatorRight.GiftCard | UserOperatorRight.SystemProduct);


            var associateEntity = imsAssociate.FirstOrDefault(ia => ia.UserId == exitUserEntity.Id);

            //新业务中 当前用户是导购 ,那么需要更新 associateEntity表即可,不用初始化其他表了
            if (associateEntity != null)
            {
                associateEntity.OperateRight = operateRight.AsId();
                associateEntity.SectionId    = section.Id;
                associateEntity.StoreId      = entity.StoreId;
                associateEntity.OperatorCode = entity.OperatorCode;

                return;
            }

            var initialBrands    = sectionbrands.Where(v => v.SectionId == section.Id);
            var initialSaleCodes = salescodes.Where(v => v.SectionId == section.Id);

            //2.1 update user level to daogou
            exitUserEntity.UserLevel   = (int)UserLevel.DaoGou;
            exitUserEntity.UpdatedDate = DateTime.Now;
            exitUserEntity.UpdatedUser = currentUserId;
            if (String.IsNullOrEmpty(exitUserEntity.Logo))
            {
                exitUserEntity.Logo = ConfigManager.IMS_DEFAULT_LOGO;
            }
            //EFHelper.Update(context, exitUserEntity);

            //2.2 create daogou's associate store


            var associate = new IMS_Associate
            {
                CreateDate   = DateTime.Now,
                CreateUser   = currentUserId,
                OperateRight = operateRight.AsId(),//inviteEntity.Inv.AuthRight.Value,<----------------------------
                Status       = 1,
                TemplateId   = ConfigManager.IMS_DEFAULT_TEMPLATE,
                UserId       = exitUserEntity.Id,
                StoreId      = entity.StoreId,
                SectionId    = section.Id,
                OperatorCode = entity.OperatorCode
            };

            var assocateEntity = context.Set <IMS_Associate>().Add(associate);

            context.SaveChanges();

            //2.3 create daogou's brands
            foreach (var brand in initialBrands)
            {
                context.Set <IMS_AssociateBrand>().Add(new IMS_AssociateBrand
                {
                    AssociateId = assocateEntity.Id,
                    BrandId     = brand.BrandId,
                    CreateDate  = DateTime.Now,
                    CreateUser  = currentUserId,
                    Status      = 1,
                    UserId      = exitUserEntity.Id
                });
            }
            //2.4 create daogou's sales code
            foreach (var saleCode in initialSaleCodes)
            {
                context.Set <IMS_AssociateSaleCode>().Add(new IMS_AssociateSaleCode
                {
                    AssociateId = assocateEntity.Id,
                    Code        = saleCode.Code,
                    CreateDate  = DateTime.Now,
                    CreateUser  = currentUserId,
                    Status      = 1,
                    UserId      = exitUserEntity.Id
                });
            }
            //2.5 create daogou's giftcard
            var giftCardEntity = giftcards.FirstOrDefault(igc => igc.Status == 1);

            if (giftCardEntity != null)
            {
                context.Set <IMS_AssociateItems>().Add(new IMS_AssociateItems
                {
                    AssociateId = assocateEntity.Id,
                    CreateDate  = DateTime.Now,
                    CreateUser  = currentUserId,
                    ItemId      = giftCardEntity.Id,
                    ItemType    = (int)ComboType.GiftCard,
                    Status      = 1,
                    UpdateDate  = DateTime.Now,
                    UpdateUser  = currentUserId
                });
            }
        }