Beispiel #1
0
 public IHttpActionResult Add([FromBody] AddModel model)
 {
     if (ModelState.IsValid)
     {
         var _goods = mapper.Map <Goods> (model);
         services.Add(_goods);
         return(Ok());
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
        /// <summary>
        /// 提交商品新增
        /// </summary>
        /// <param name="files"></param>
        /// <param name="g"></param>
        /// <returns></returns>
        public ActionResult TjAdd(HttpPostedFileBase[] files, Goods g)
        {
            if (files[0] != null)
            {
                try
                {
                    var path = Server.MapPath("/tp");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    foreach (HttpPostedFileBase item in files)
                    {
                        string name = "";

                        Random rd = new Random();
                        string i  = rd.Next().ToString();
                        name       = i + ".jpg";
                        g.GoodsPic = "tp/" + name;

                        item.SaveAs(Path.Combine(path, name));
                    }
                    DateTime sj = DateTime.Now;
                    g.GoodsTime = sj;
                    bool i2 = gs.Add(g);
                    if (i2)
                    {
                        return(Content(Ts("添加成功", "../Frontdesk/product_category")));
                    }
                    else
                    {
                        return(Content(Ts("添加失败", "../Frontdesk/AddPro")));
                    }
                }
                catch (Exception ex)
                {
                    return(Content(string.Format("上传文件出现异常:{0}", ex.Message)));
                }
            }
            else
            {
                return(Content(Ts("请选择图片", "../Frontdesk/AddPro")));
            }
        }
        public ActionResult AddGoods(Goods good, SaleInfo sale)
        {
            UserInfo user = CurrentLoginUser;

            if (user == null)
            {
                return(Redirect("/Account/login"));
            }

            good.DelGlag = normal;
            good.SubTime = DateTime.Now;

            var shops = ListShopsServices.LoadEntities(u => u.UserInfoId == CurrentLoginUser.Id).FirstOrDefault();

            good.ShopingId = shops.Id;

            try
            {
                GoodsServices.Add(user, good, sale);

                #region Luncene创建索引
                JobSerach search = new JobSerach();
                search.Id           = good.Id;
                search.Title        = good.Title;
                search.Price        = (double)good.Price;
                search.ImageAddress = good.SmallImageAddress;
                search.Content      = good.Descript;
                search.MaiDian      = good.MaiDian;

                IndexManager.myManager.Add(search);
                #endregion



                return(Content("ok"));
            }
            catch (Exception)
            {
                return(Content("数据错误,请联系管理员"));

                throw;
            }
        }
        public void GetAll_Test()
        {
            authService.Add(new User());
            authService.Add(new User());
            authService.Add(new User());
            goodsService.Add(new Goods());
            shopOrderService.Add(new ShopOrder());
            shopOrderService.Add(new ShopOrder());
            typeOfGoodsService.Add(new TypeOfGoods());
            typeOfGoodsService.Add(new TypeOfGoods());
            typeOfGoodsService.Add(new TypeOfGoods());

            var statistic = new StatisticService(authService, goodsService, typeOfGoodsService, shopOrderService).Get();

            Assert.AreEqual(statistic.TotalCountOfGoods, 1);
            Assert.AreEqual(statistic.TotalCountOfGoodsTypes, 3);
            Assert.AreEqual(statistic.TotalCountOfUsers, 3);
            Assert.AreEqual(statistic.TotalCountOfOrders, 2);
        }