示例#1
0
        /// <summary>
        /// 编辑产品
        /// </summary>
        /// <param name="mproduct"></param>
        /// <param name="productimgurl"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public string EditeProduct(Mproduct mproduct, HttpPostedFileBase productimgurl, string path)
        {
            MwxResult mwxResult = new MwxResult()
            {
                errcode = -1
            };

            if (productimgurl != null)
            {
                string savePath = string.Empty;
                string fileSave = FileOpert.UploadImg(productimgurl, path + "uploadFile\\" + System.DateTime.Now.ToString("yyyy") + "\\", out savePath);
                if (string.IsNullOrEmpty(fileSave))
                {
                    mproduct.productimgurl = savePath.Replace(path, "");
                }
            }

            bool addResult = new ProductService().UpdateProdctPrice(mproduct.productid,
                                                                    (decimal)mproduct.origprice, (decimal)mproduct.sellprice, (int)mproduct.stock, (int)mproduct.priority, mproduct);

            if (addResult)
            {
                mwxResult.errmsg              = "保存成功!";
                mwxResult.errcode             = 0;
                CacheData.allRecommendPro     = null;
                CacheData.allRecommendProList = null;
            }
            else
            {
                mwxResult.errmsg = "保存失败!";
            }

            return(JsonHelper.GetJson <MwxResult>(mwxResult));
        }
        /// <summary>
        /// 新增文章
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string AddNews(Mnews model, HttpPostedFileBase productimgurl = null, string path = "", int type = 1)
        {
            MwxResult mwxResult = new MwxResult()
            {
                errcode = -1
            };

            string savePath = string.Empty;

            //// 存图片
            if (productimgurl != null)
            {
                string fileSave = FileOpert.UploadImg(productimgurl, path + "uploadFile\\" + System.DateTime.Now.ToString("yyyy") + "\\", out savePath);
                if (string.IsNullOrEmpty(fileSave))
                {
                    model.img = savePath.Replace(path, "");
                }
            }

            try
            {
                if (string.IsNullOrEmpty(model.id))
                {
                    DateTime dateTimeNow = System.DateTime.Now;
                    model.isDelete    = "0";
                    model.isEffective = "1";
                    model.great_time  = dateTimeNow;
                    model.modify_time = dateTimeNow;
                    model.type        = type;
                    model.id          = PublicTools.GetRandomNumberByTime();
                    if (new NewsService().AddNews(model))
                    {
                        mwxResult.errcode = 0;
                        mwxResult.errmsg  = "操作成功!";
                    }
                    else
                    {
                        mwxResult.errmsg = "操作失败!";
                    }
                }
                else
                {
                    if (new NewsService().UpdateNews(model))
                    {
                        mwxResult.errcode = 0;
                        mwxResult.errmsg  = "操作成功!";
                    }
                    else
                    {
                        mwxResult.errmsg = "操作失败!";
                    }
                }
            }
            catch (Exception ex)
            {
                mwxResult.errmsg = "操作失败!";
            }

            return(JsonHelper.GetJson <MwxResult>(mwxResult));
        }
示例#3
0
        /// <summary>
        /// 新增产品
        /// </summary>
        /// <param name="mproduct"></param>
        /// <param name="productimgurl"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public string AddProduct(Mproduct mproduct, HttpPostedFileBase productimgurl, string path)
        {
            MwxResult mwxResult = new MwxResult()
            {
                errcode = -1
            };

            //// 实现步骤
            //// 1.数据合法性验证
            //// 2.图片入库
            //// 3.数据落地
            string savePath = string.Empty;

            mwxResult.errmsg = this.CheckedProduct(mproduct);

            if (productimgurl == null)
            {
                mwxResult.errmsg = "产品图片不能为空!";
                return(JsonHelper.GetJson <MwxResult>(mwxResult));
            }

            if (!string.IsNullOrEmpty(mwxResult.errmsg))
            {
                return(JsonHelper.GetJson <MwxResult>(mwxResult));
            }

            //// 存图片
            string fileSave = FileOpert.UploadImg(productimgurl, path + "uploadFile\\" + System.DateTime.Now.ToString("yyyy") + "\\", out savePath);

            if (string.IsNullOrEmpty(fileSave))
            {
                mproduct.productimgurl = savePath.Replace(path, "");
            }
            else
            {
                //// 构建错误信息并返回
                mwxResult.errmsg = fileSave;
                return(JsonHelper.GetJson <MwxResult>(mwxResult));
            }

            mproduct.productid = PublicTools.GetRandomNumberByTime();
            ///// 入库
            bool addResult = new ProductService().AddProduct(mproduct);

            if (addResult)
            {
                mwxResult.errmsg              = "新增成功!";
                mwxResult.errcode             = 0;
                CacheData.allRecommendPro     = null;
                CacheData.allRecommendProList = null;
            }
            else
            {
                mwxResult.errmsg = "新增失败!";
            }

            return(JsonHelper.GetJson <MwxResult>(mwxResult));
        }
示例#4
0
        /// <summary>
        /// 编辑产品类别
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string EditProductclass(Mproductclass model, HttpPostedFileBase productimgurl, string path)
        {
            MwxResult mwxResult = new MwxResult()
            {
                errcode = -1
            };

            try
            {
                //// 数据合法性检查
                if (model == null || model.classid < 1 || string.IsNullOrEmpty(model.classname))
                {
                    mwxResult.errmsg = "操作失败,新增数据不能为空!";
                }

                if (productimgurl != null)
                {
                    string savePath = string.Empty;
                    string fileSave = FileOpert.UploadImg(productimgurl, path + "uploadFile\\" + System.DateTime.Now.ToString("yyyy") + "\\", out savePath);
                    if (string.IsNullOrEmpty(fileSave))
                    {
                        model.imgpath = savePath.Replace(path, "");
                    }
                }

                //// 数据落地入库
                if (!new ProductclassService().EditProductclass(model))
                {
                    mwxResult.errmsg = "操作失败";
                }
                else
                {
                    mwxResult.errcode         = 0;
                    mwxResult.errmsg          = "操作成功";
                    CacheData.allProductClass = null;
                }
            }
            catch (Exception ex)
            {
                mwxResult.errmsg = "操作失败:系统异常!";
            }

            return(JsonHelper.GetJson <MwxResult>(mwxResult));
        }
示例#5
0
        /// <summary>
        /// 新增产品类别
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string AddProductclasses(Mproductclass model, HttpPostedFileBase productimgurl, string path)
        {
            MwxResult mwxResult = new MwxResult()
            {
                errcode = -1
            };

            try
            {
                //// 数据合法性检查
                if (model == null || string.IsNullOrEmpty(model.classname))
                {
                    mwxResult.errmsg = "操作失败,新增数据不能为空!";
                }

                if (productimgurl == null)
                {
                    mwxResult.errmsg = "图片不能为空!";
                    return(JsonHelper.GetJson <MwxResult>(mwxResult));
                }

                string savePath = string.Empty;

                //// 存图片
                string fileSave = FileOpert.UploadImg(productimgurl, path + "uploadFile\\" + System.DateTime.Now.ToString("yyyy") + "\\", out savePath);
                if (string.IsNullOrEmpty(fileSave))
                {
                    model.imgpath = savePath.Replace(path, "");
                }
                else
                {
                    //// 构建错误信息并返回
                    mwxResult.errmsg = fileSave;
                    return(JsonHelper.GetJson <MwxResult>(mwxResult));
                }

                //// 时间相关参数赋值
                model.great_time  = System.DateTime.Now;
                model.modify_time = model.great_time;
                model.isDelete    = 0;
                model.isEffective = 1;

                //// 数据落地入库
                if (!new ProductclassService().AddProductclass(model))
                {
                    mwxResult.errmsg = "操作失败";
                }
                else
                {
                    mwxResult.errcode         = 0;
                    mwxResult.errmsg          = "操作成功";
                    CacheData.allProductClass = null;
                }
            }
            catch (Exception ex)
            {
                mwxResult.errmsg = "操作失败:系统异常!";
            }

            return(JsonHelper.GetJson <MwxResult>(mwxResult));
        }