/// <summary> /// 根据食谱编号移除整个食谱信息 /// </summary> /// <param name="recipesId"></param> /// <param name="phone"></param> /// <returns></returns> public Result RemoveRecipesById(int recipesId, long phone) { Result result = new Result() { Status = true, Message = "删除食谱成功" }; try { if (recipesId == 0) { throw new ArgumentNullException("删除食谱,参数非法"); } //食谱缓存服务 IRecipesCache recipesservice = ServiceObjectContainer.Get <IRecipesCache>(); IRelationShareInfoCache relationservice = ServiceObjectContainer.Get <IRelationShareInfoCache>(); //删除食谱绑定关系 bool cannext = false; cannext = DBConnectionManager.Instance.Writer.Update(new RelationShareDeleteSpefication(recipesId.ToString(), phone, 0).Satifasy()); if (cannext) { cannext = false; //修改食谱信息为禁用 cannext = DBConnectionManager.Instance.Writer.Update(new RecipesDeleteSpefication(recipesId.ToString(), 0).Satifasy()); } if (!cannext) { DBConnectionManager.Instance.Writer.Rollback(); result.Status = false; result.Message = "删除食谱失败,请确保请求数据合法"; } else { DBConnectionManager.Instance.Writer.Commit(); relationservice.RemoveRelationShareByRecipes(recipesId, phone); recipesservice.SetRecipesEnable(recipesId, false); } } catch (Exception ex) { DBConnectionManager.Instance.Writer.Rollback(); result.Status = false; result.Message = "删除食谱出错:" + ex.Message; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:RemoveRecipesById() .RecipesService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 根据食谱编号获取收藏的单品集合 /// </summary> /// <param name="recipesId"></param> /// <returns></returns> public Result <IList <Dish> > GetCollectDishList(int recipesId) { Result <IList <Dish> > result = new Result <IList <Dish> >() { Data = new List <Dish>(), Message = "查询单品信息集合成功", Status = true }; try { //获取分享关系集合 IRelationShareInfoCache relationcache = ServiceObjectContainer.Get <IRelationShareInfoCache>(); IList <RelationShareInfo> relationshares = relationcache.GetRelationShareByReceipId(recipesId); //查询单品信息 if (relationshares != null && relationshares.Count > 0) { IDishCache dishcache = ServiceObjectContainer.Get <IDishCache>(); IList <int> dishIds = new List <int>(); foreach (var share in relationshares) { DishInfo dish = dishcache.GetDishInfoById(share.DishId); result.Data.Add(dish.Copy <Dish>()); } } } catch (Exception ex) { result.Status = false; result.Message = "查询分享单品食物出错:" + ex.Message; result.StatusCode = "GSD001"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:GetCollectDishList() .DishService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 收藏单品食物到食谱 /// </summary> /// <param name="collect"></param> /// <returns></returns> public Result CollectDishInfo(DishCollect collect) { Result result = new Result() { Status = true, StatusCode = "CD000", Message = "收藏单品食物成功" }; try { IRecipesCache recipesservice = ServiceObjectContainer.Get <IRecipesCache>(); IRelationShareInfoCache relationservice = ServiceObjectContainer.Get <IRelationShareInfoCache>(); RecipesInfo updaterecipes = null; IList <RelationShareInfo> shareinfo = null; //新增一条单品记录 bool cannext = false; //新增一条单品与食谱关系记录 if (cannext) { cannext = false; shareinfo = new List <RelationShareInfo>(); RelationShareInfo sharerelation = new RelationShareInfo() { DishId = collect.DIshId, Phone = collect.Phone, RecipesId = collect.RecipesId, UpdateDate = DateTime.Now }; shareinfo.Add(sharerelation); cannext = DBConnectionManager.Instance.Writer.Insert(new RelationShareAddSpefication(shareinfo).Satifasy()); } //更新食谱信息(更新操作时间) if (cannext) { cannext = false; updaterecipes = recipesservice.GetRecipesInfoById(collect.RecipesId); if (updaterecipes == null) { throw new ArgumentNullException("收藏食物,食谱参数不能为空"); } 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(); //更新缓存 recipesservice.SaveInfo(updaterecipes); foreach (RelationShareInfo item in shareinfo) { relationservice.SaveInfo(item); } } } catch (Exception ex) { DBConnectionManager.Instance.Writer.Rollback(); result.Status = false; result.Message = "收藏单品食物失败" + ex.Message; result.StatusCode = "CD001"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:CollectDishInfo() .DishService"), LogType.ErrorLog); } return(result); }
/// <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); }