示例#1
0
        private void Bind()
        {
            Guid adItemId = Guid.Empty;

            Guid.TryParse(Request.QueryString["adItemId"], out adItemId);
            if (!adItemId.Equals(Guid.Empty))
            {
                AdItemLink bll   = new AdItemLink();
                var        model = bll.GetModel(adItemId);
                if (model != null)
                {
                }
            }
        }
        /// <summary>
        /// 广告项链接提交
        /// </summary>
        /// <param name="context"></param>
        private void SaveAdItemLink(HttpContext context)
        {
            try
            {
                Guid adId = Guid.Empty;
                if (!string.IsNullOrWhiteSpace(context.Request.Form["adId"]))
                {
                    Guid.TryParse(context.Request.Form["adId"], out adId);
                }
                if (adId.Equals(Guid.Empty))
                {
                    context.Response.Write("{\"success\": false,\"message\": \"请先完成基本信息\"}");
                    return;
                }

                Guid adItemId = Guid.Empty;
                if (!string.IsNullOrWhiteSpace(context.Request.Form["adItemId"]))
                {
                    Guid.TryParse(context.Request.Form["adItemId"], out adItemId);
                }
                if (adItemId.Equals(Guid.Empty))
                {
                    context.Response.Write("{\"success\": false,\"message\": \"请先完成广告项再继续此操作\"}");
                    return;
                }

                if (string.IsNullOrWhiteSpace(context.Request.Form["txtUrl"]))
                {
                    context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Params_InvalidError + "\"}");
                    return;
                }
                var productId = Guid.Empty;
                if (!string.IsNullOrWhiteSpace(context.Request.Form["productId"]))
                {
                    Guid.TryParse(context.Request.Form["productId"], out productId);
                }

                AdItemLink bll = new AdItemLink();

                AdItemLinkInfo model = new AdItemLinkInfo();
                model.AdItemId  = adItemId;
                model.Url       = context.Request.Form["txtUrl"].Trim();
                model.ProductId = productId;

                int effect = -1;

                if (bll.IsExist(adItemId))
                {
                    effect = bll.Update(model);
                }
                else
                {
                    effect = bll.Insert(model);
                }

                if (effect == 110)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Exist + "\"}");
                    return;
                }
                if (effect != 1)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"操作失败,原因:请正确输入并重试,如果再出现此问题请联系管理员\"}");
                    return;
                }

                context.Response.Write("{\"success\": true,\"message\": \"" + MessageContent.Submit_Success + "\"}");
            }
            catch (Exception ex)
            {
                context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.AlertTitle_Ex_Error + ":" + ex.Message + "\"}");
            }
        }
        /// <summary>
        /// 广告项提交
        /// </summary>
        /// <param name="context"></param>
        private void SaveAdItem(HttpContext context)
        {
            try
            {
                Guid adId = Guid.Empty;
                if (!string.IsNullOrWhiteSpace(context.Request.Form["adId"]))
                {
                    Guid.TryParse(context.Request.Form["adId"], out adId);
                }
                if (adId.Equals(Guid.Empty))
                {
                    context.Response.Write("{\"success\": false,\"message\": \"请先完成基本信息\"}");
                    return;
                }

                if (string.IsNullOrWhiteSpace(context.Request.Form["ddlActionType"]))
                {
                    context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Params_InvalidError + "\"}");
                    return;
                }

                Guid adItemId = Guid.Empty;
                if (!string.IsNullOrWhiteSpace(context.Request.Form["hAdItemId"]))
                {
                    Guid.TryParse(context.Request.Form["hAdItemId"], out adItemId);
                }
                Guid pictureId = Guid.Empty;
                if (!string.IsNullOrWhiteSpace(context.Request.Form["hImgPictureId"]))
                {
                    Guid.TryParse(context.Request.Form["hImgPictureId"], out pictureId);
                }
                Guid actionTypeId = Guid.Empty;
                if (!string.IsNullOrWhiteSpace(context.Request.Form["ddlActionType"]))
                {
                    Guid.TryParse(context.Request.Form["ddlActionType"], out actionTypeId);
                }
                int sort = 0;
                if (!string.IsNullOrWhiteSpace(context.Request.Form["txtSort"]))
                {
                    int.TryParse(context.Request.Form["txtSort"], out sort);
                }
                bool isDisable = false;
                if (!string.IsNullOrWhiteSpace(context.Request.Form["isDisable"]))
                {
                    bool.TryParse(context.Request.Form["isDisable"], out isDisable);
                }

                AdItem bll = new AdItem();

                AdItemInfo model = new AdItemInfo();
                model.AdvertisementId = adId;
                model.Id           = adItemId;
                model.PictureId    = pictureId;
                model.ActionTypeId = actionTypeId;
                model.Sort         = sort;
                model.IsDisable    = isDisable;

                int effect = -1;

                if (!adItemId.Equals(Guid.Empty))
                {
                    var oldModel = bll.GetModel(adItemId);
                    if (oldModel.ActionTypeId != model.ActionTypeId)
                    {
                        AdItemLink adlBll = new AdItemLink();
                        if (adlBll.Delete(adItemId) < 1)
                        {
                            AdItemContent adcBll = new AdItemContent();
                            adcBll.Delete(adItemId);
                        }
                    }
                    else
                    {
                        effect = bll.Update(model);
                    }
                }
                else
                {
                    model.Id = Guid.NewGuid();
                    effect   = bll.Insert(model);
                }

                if (effect == 110)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Exist + "\"}");
                    return;
                }
                if (effect != 1)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"操作失败,原因:请正确输入并重试,如果再出现此问题请联系管理员\"}");
                    return;
                }

                context.Response.Write("{\"success\": true,\"message\": \"" + MessageContent.Submit_Success + "\",\"data\": \"" + model.Id + "\"}");
            }
            catch (Exception ex)
            {
                context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.AlertTitle_Ex_Error + ":" + ex.Message + "\"}");
            }
        }