/// <summary>
        /// 团购商品
        /// </summary>
        /// <param name="request">
        /// 数据源请求信息对象
        /// </param>
        /// <param name="groupBuy">
        /// 团购商品对象
        /// </param>
        /// <returns>
        /// 执行方法结果
        /// </returns>
        public ActionResult AddGroupBuy([DataSourceRequest] DataSourceRequest request, ChannelGroupBuyModel groupBuy)
        {
            try
            {
                if (groupBuy != null)
                {
                    this.channelGroupBuyService = new ChannelGroupBuyService();
                    var channelGroupBuy = DataTransfer.Transfer<Channel_GroupBuy>(groupBuy, typeof(ChannelGroupBuyModel));
                    channelGroupBuy.ID = this.channelGroupBuyService.Insert(channelGroupBuy);
                    if (channelGroupBuy.ID > 0)
                    {
                        return Json(new[] { channelGroupBuy }.ToDataSourceResult(request, this.ModelState));
                    }
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.View();
        }
        public void AddGroupBuy()
        {
            var channelGroupBuyModel = new ChannelGroupBuyModel();
            if (!string.IsNullOrEmpty(Request.Form["productId"]))
            {
                channelGroupBuyModel.ProductID = int.Parse(Request.Form["productId"]);
            }

            if (!string.IsNullOrEmpty(Request.Form["GroupBuyName"]))
            {
                channelGroupBuyModel.Name = Request.Form["GroupBuyName"];
            }
            if (!string.IsNullOrEmpty(Request.Form["startTime"]))
            {
                channelGroupBuyModel.StartTime = DateTime.Parse(Request.Form["startTime"]);
            }
            if (!string.IsNullOrEmpty(Request.Form["endTime"]))
            {
                channelGroupBuyModel.EndTime = DateTime.Parse(Request.Form["endTime"]);
            }
            if (!string.IsNullOrEmpty(Request.Form["levelID"]))
            {
                channelGroupBuyModel.UserLevelID = int.Parse(Request.Form["levelID"]);
            }
            if (!string.IsNullOrEmpty(Request.Form["Level"]))
            {
                channelGroupBuyModel.ShowLevel = int.Parse(Request.Form["Level"]);
            }

            if (!string.IsNullOrEmpty(Request.Form["isShowTime"]))
            {
                channelGroupBuyModel.IsShowTime = bool.Parse(Request.Form["isShowTime"]);
            }
            if (!string.IsNullOrEmpty(Request.Form["IsOnlinePayment"]))
            {
                channelGroupBuyModel.IsOnlinePayment = bool.Parse(Request.Form["IsOnlinePayment"]);
            }
            if (!string.IsNullOrEmpty(Request.Form["totalNumber"]))
            {
                channelGroupBuyModel.TotalNumber = int.Parse(Request.Form["totalNumber"]);
            }
            if (!string.IsNullOrEmpty(Request.Form["gbPrice"]))
            {
                channelGroupBuyModel.GBPrice = double.Parse(Request.Form["gbPrice"]);
            }
            if (!string.IsNullOrEmpty(Request.Form["soldOfReality"]))
            {
                channelGroupBuyModel.SoldOfReality = int.Parse(Request.Form["soldOfReality"]);
            }
            if (!string.IsNullOrEmpty(Request.Form["soldOfVirtual"]))
            {
                channelGroupBuyModel.SoldOfVirtual = int.Parse(Request.Form["soldOfVirtual"]);
            }
            if (!string.IsNullOrEmpty(Request.Form["pageView"]))
            {
                channelGroupBuyModel.PageView = int.Parse(Request.Form["pageView"]);
            }
            if (!string.IsNullOrEmpty(Request.Form["beizhu"]))
            {
                channelGroupBuyModel.Introduce = Request.Form["beizhu"];
            }
            else
            {
                channelGroupBuyModel.Introduce = " ";
            }
            channelGroupBuyModel.CreateTime = DateTime.Now;
            channelGroupBuyModel.Status = 2;
            this.channelGroupBuyService = new ChannelGroupBuyService();
            var channelGroupBuy = DataTransfer.Transfer<Channel_GroupBuy>(channelGroupBuyModel, typeof(ChannelGroupBuyModel));

            //根据商品的ID但询是否在团购列表里面商品已经参加团购,此时修改团购数据
            try
            {
                List<Channel_GroupBuy> listProduct = channelGroupBuyService.QueryGroupBuyByProductId(channelGroupBuyModel.ProductID);
                if (listProduct.Count > 0)
                {
                    this.channelGroupBuyService.UpdateGroupBuyProductId(channelGroupBuy);
                }
                else
                {
                    this.channelGroupBuyService.Insert(channelGroupBuy);
                }
            }
            catch (Exception exception)
            {
                Response.Write("添加失败");
                throw new Exception(exception.Message, exception);
            }

            Response.Write("添加成功");
        }
        /// <summary>
        /// 图片上传
        /// </summary>
        /// <param name="pictureUpload">上传的图片</param>
        /// <param name="productId">对应商品的ID</param>
        /// <returns></returns>
        public ActionResult UploadPicture(IEnumerable<HttpPostedFileBase> pictureUpload, string productId)
        {
            if (pictureUpload == null)
            {
                return Json(string.Empty);
            }

            try
            {
                foreach (var file in pictureUpload)
                {
                    var displayName = Path.GetFileName(file.FileName);
                    var fileName = Guid.NewGuid().ToString();

                    var rootPath = this.Server.MapPath("~/Images/Channel/");
                    var path = rootPath + DateTime.Now.Year + "\\" + DateTime.Now.Month + DateTime.Now.Day + "\\";
                    var thumbnailPath = rootPath + DateTime.Now.Year + "\\" + DateTime.Now.Month + DateTime.Now.Day + "\\Thumbnail\\";
                    if (displayName == null)
                    {
                        continue;
                    }

                    var filePath = "/Images/Channel/" + DateTime.Now.Year + "/" + DateTime.Now.Month + DateTime.Now.Day + "/" + fileName + "." + displayName.Split('.')[1];

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    if (!Directory.Exists(thumbnailPath))
                    {
                        Directory.CreateDirectory(thumbnailPath);
                    }

                    file.SaveAs(path + fileName + "." + fileName);
                    var groupbuy = new ChannelGroupBuyModel
                    {
                        ProductID = int.Parse(productId),
                        Name = " ",
                        UserLevelID = 1,
                        CreateTime = DateTime.Now,
                        GBPrice = 1,
                        TotalNumber = 1,
                        ShowLevel = 1,
                        StartTime = DateTime.Now,
                        EndTime = DateTime.Now,
                        SoldOfReality = 1,
                        SoldOfVirtual = 1,
                        PageView = 1,
                        Status = 0,
                        ImageUrl = "///",
                        Introduce = "///"
                    };
                    channelGroupBuyService = new ChannelGroupBuyService();
                    if (channelGroupBuyService.QueryGroupBuyByProductId(groupbuy.ProductID).Count > 0)
                    {
                        channelGroupBuyService.UpdateImg(groupbuy.ProductID, filePath);
                    }
                    else
                    {
                        var groupBuyModel = DataTransfer.Transfer<Channel_GroupBuy>(groupbuy, typeof(ChannelGroupBuyModel));
                        channelGroupBuyService.Insert(groupBuyModel);
                        channelGroupBuyService.UpdateImg(groupBuyModel.ProductID, filePath);
                    }
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.Json(string.Empty);
        }