Esempio n. 1
0
        /// <summary>
        /// 保存spreadinfo
        /// </summary>
        /// <param name="spreadInfo"></param>
        /// <param name="isDeleteOld">是否删除同类型的旧数据</param>
        public void BuildSaveSpreadInfo(SpreadInfoDTO spreadInfo, bool isDeleteOld = false)
        {
            if (spreadInfo == null || spreadInfo.SpreadId == Guid.Empty || spreadInfo.SpreadCode == Guid.Empty)
            {
                return;
            }
            ContextSession contextSession = ContextFactory.CurrentThreadContext;

            if (isDeleteOld)
            {
                //插入SpreadInfo数据库表
                var oldSpreadInfo = SpreadInfo.ObjectSet().FirstOrDefault(c => c.SpreadId == spreadInfo.SpreadId && c.IsDel == 0);

                if (oldSpreadInfo != null)
                {
                    if ((oldSpreadInfo.SpreadId == spreadInfo.SpreadId) && (oldSpreadInfo.SpreadType == spreadInfo.SpreadType))
                    {
                        oldSpreadInfo.EntityState = EntityState.Deleted;
                    }
                }
            }
            SpreadInfo newSpreadInfo = SpreadInfo.CreateSpreadInfo();

            newSpreadInfo.SpreadId   = spreadInfo.SpreadId;
            newSpreadInfo.SpreadCode = spreadInfo.SpreadCode;
            newSpreadInfo.SpreadUrl  = spreadInfo.SpreadUrl;
            newSpreadInfo.IsDel      = spreadInfo.IsDel;
            newSpreadInfo.SpreadType = spreadInfo.SpreadType;
            newSpreadInfo.SpreadDesc = spreadInfo.SpreadDesc;
            newSpreadInfo.AppId      = spreadInfo.AppId;
            contextSession.SaveObject(newSpreadInfo);
            UpdateRalationUserSpread(spreadInfo.SpreadId, spreadInfo.SpreadCode, spreadInfo.SpreadType);
        }
Esempio n. 2
0
        /// <summary>
        /// 更新用户为推广主
        /// </summary>
        /// <param name="spreaderDto">推广者dto</param>
        /// <returns></returns>
        public ResultDTO UpdateToSpreaderExt(SpreaderAndBuyerWxDTO spreaderDto)
        {
            ResultDTO result = new ResultDTO {
                Message = "Success"
            };

            if (spreaderDto == null || spreaderDto.SpreaderId == Guid.Empty || spreaderDto.SpreadCode == Guid.Empty)
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "id为空或推广码为空"
                });
            }
            try
            {
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                //插入SpreadInfo数据库表
                var oldSpreadInfo = SpreadInfo.ObjectSet().FirstOrDefault(c => c.SpreadId == spreaderDto.SpreaderId && c.SpreadCode == spreaderDto.SpreadCode && c.IsDel == 0);
                if (oldSpreadInfo == null)
                {
                    SpreadInfo newSpreadInfo = SpreadInfo.CreateSpreadInfo();
                    newSpreadInfo.SpreadId   = spreaderDto.SpreaderId;
                    newSpreadInfo.SpreadCode = spreaderDto.SpreadCode;
                    newSpreadInfo.IsDel      = 0;
                    newSpreadInfo.SpreadType = 0;
                    contextSession.SaveObject(newSpreadInfo);
                    contextSession.SaveChanges();
                }
                var createUser      = EBCSV.GetOrgCreateUser(spreaderDto.SpreaderId);
                var oldUserSpreader = UserSpreader.ObjectSet().FirstOrDefault(c => c.UserId == createUser);
                if (oldUserSpreader != null)
                {
                    var createUsers = EBCSV.GetMyCreateAccountList(createUser);
                    if (createUsers != null && createUsers.Contains(oldUserSpreader.SpreaderId))
                    {
                        return(result);
                    }
                    oldUserSpreader.EntityState = EntityState.Deleted;
                }
                UserSpreader newUserSpreader = UserSpreader.CreateUserSpreader();
                newUserSpreader.SpreaderId = spreaderDto.SpreaderId;
                newUserSpreader.UserId     = createUser;
                newUserSpreader.SpreadCode = spreaderDto.SpreadCode;
                contextSession.SaveObject(newUserSpreader);
                contextSession.SaveChanges();
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("UserSpreaderSV.UpdateToSpreaderExt异常:spreaderDto:{0}", JsonHelper.JsonSerializer(spreaderDto)), ex);
                return(result);
            }
            return(result);
        }