Пример #1
0
        public JsonResult ShareDish(int shopId, int recipesId)
        {
            IDishService    dish          = ServiceObjectContainer.Get <IDishService>();
            IRecipesService recipes       = ServiceObjectContainer.Get <IRecipesService>();
            IShopService    shop          = ServiceObjectContainer.Get <IShopService>();
            Shop            shopselect    = shop.GetShopInfoById(shopId).Data;
            Recipes         recipesselect = recipes.GetRecipesById(recipesId).Data;

            Dish dishmodel = new Dish();

            dishmodel.DishId      = Generation.GenerationId();
            dishmodel.Name        = "黑椒牛柳";
            dishmodel.Type        = Model.Enum.DishType.川菜.GetHashCode();
            dishmodel.MealTime    = Model.Enum.MealTime.午餐.GetHashCode();
            dishmodel.UpdateDate  = DateTime.Now;
            dishmodel.Image       = "";
            dishmodel.Description = "测试单品";
            dishmodel.ShopId      = shopselect.ShopId;
            dishmodel.ShopName    = shopselect.ShopName;

            DishShare share = new DishShare();

            share.DishInfo    = dishmodel;
            share.RecipesInfo = recipesselect;
            share.ShopInfo    = shopselect;

            return(Json(dish.ShareDishInfo(share)));
        }
Пример #2
0
        public JsonResult DishShare(Dish dish, int shopid, int recipeid)
        {
            IDishService    dishservice    = ServiceObjectContainer.Get <IDishService>();
            IRecipesService recipesservice = ServiceObjectContainer.Get <IRecipesService>();
            IShopService    shopservice    = ServiceObjectContainer.Get <IShopService>();
            Shop            shopselect     = shopservice.GetShopInfoById(shopid).Data;
            Recipes         recipesselect  = recipesservice.GetRecipesById(recipeid).Data;

            dish.DishId     = Generation.GenerationId();
            dish.UpdateDate = DateTime.Now;
            dish.ShopId     = shopselect.ShopId;
            dish.ShopName   = shopselect.ShopName;
            if (!string.IsNullOrEmpty(dish.Image))
            {
                int substringindex = dish.Image.LastIndexOf(',') + 1;
                dish.Image = dish.Image.Substring(substringindex, dish.Image.Length - substringindex);
            }



            DishShare share = new DishShare();

            share.DishInfo    = dish;
            share.RecipesInfo = recipesselect;
            share.ShopInfo    = shopselect;

            return(Json(dishservice.ShareDishInfo(share)));
        }
Пример #3
0
        /// <summary>
        /// 分享单品食物信息
        /// </summary>
        /// <param name="share"></param>
        /// <returns></returns>
        public Result ShareDishInfo(DishShare share)
        {
            Result result = new Result()
            {
                Status     = true,
                StatusCode = "SSD000",
                Message    = "分享单品食物成功"
            };

            try
            {
                //新增一条单品记录
                bool        cannext                 = false;
                DishInfo    dishinfo                = share.DishInfo.Copy <DishInfo>();
                ShopInfo    updateshop              = share.ShopInfo.Copy <ShopInfo>();
                RecipesInfo updaterecipes           = share.RecipesInfo.Copy <RecipesInfo>();
                IList <RelationShareInfo> shareinfo = null;
                if (dishinfo == null)
                {
                    throw new ArgumentNullException("创建食物,单品食物参数不能为空");
                }
                if (updateshop == null)
                {
                    throw new ArgumentNullException("创建食物,门店信息参数不能为空");
                }
                if (updaterecipes == null)
                {
                    throw new ArgumentNullException("创建食物,食谱参数不能为空");
                }

                cannext = DBConnectionManager.Instance.Writer.Insert(new DishAddSpefication(dishinfo).Satifasy());

                //新增一条单品与食谱关系记录
                if (cannext)
                {
                    cannext   = false;
                    shareinfo = new List <RelationShareInfo>();
                    RelationShareInfo sharerelation = new RelationShareInfo()
                    {
                        DishId     = dishinfo.DIshId,
                        Phone      = share.RecipesInfo.Phone,
                        RecipesId  = share.RecipesInfo.RecipesId,
                        UpdateDate = DateTime.Now
                    };
                    shareinfo.Add(sharerelation);
                    cannext = DBConnectionManager.Instance.Writer.Insert(new RelationShareAddSpefication(shareinfo).Satifasy());
                }
                //更新门店信息(更新操作时间)
                if (cannext)
                {
                    updateshop.UpdateDate = DateTime.Now;
                    cannext = DBConnectionManager.Instance.Writer.Update(new ShopUpdateSpefication(updateshop).Satifasy());
                }
                //更新食谱信息(更新操作时间)
                if (cannext)
                {
                    updaterecipes.UpdateDate = DateTime.Now;
                    cannext = DBConnectionManager.Instance.Writer.Update(new RecipesUpdateSpefication(updaterecipes).Satifasy());
                }

                if (!cannext)
                {
                    DBConnectionManager.Instance.Writer.Rollback();
                    result.Status  = false;
                    result.Message = "分享单品食物失败,请确保请求数据合法";
                }
                else
                {
                    DBConnectionManager.Instance.Writer.Commit();

                    //更新缓存
                    IRelationShareInfoCache shareservice = ServiceObjectContainer.Get <IRelationShareInfoCache>();
                    foreach (RelationShareInfo item in shareinfo)
                    {
                        shareservice.SaveInfo(item);
                    }


                    IDishCache dishservice = ServiceObjectContainer.Get <IDishCache>();
                    dishservice.SaveInfo(dishinfo);

                    IShopCache shopservice = ServiceObjectContainer.Get <IShopCache>();
                    shopservice.SaveInfo(updateshop);

                    IRecipesCache recipesservice = ServiceObjectContainer.Get <IRecipesCache>();
                    recipesservice.SaveInfo(updaterecipes);
                }
            }
            catch (Exception ex)
            {
                DBConnectionManager.Instance.Writer.Rollback();
                result.Status     = false;
                result.Message    = "分享单品食物失败:" + ex.Message;
                result.StatusCode = "SSD001";
                LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:ShareDishInfo() .DishService"), LogType.ErrorLog);
            }
            return(result);
        }