Ejemplo n.º 1
0
        /// <summary>
        /// 设置食谱禁启用状态
        /// </summary>
        /// <param name="recipesId">食谱编号</param>
        /// <param name="enable">
        /// true:启用
        /// false:禁用
        /// </param>
        /// <returns></returns>
        public bool SetRecipesEnable(int recipesId, bool enable)
        {
            if (recipesId == 0)
            {
                throw new ArgumentNullException("recipesId can not be zero");
            }
            bool result = false;

            string key = string.Format("DB_RI_{0}_*", recipesId);

            RecipesInfo    updateinfo = null;
            IList <string> keys       = Session.Current.ScanAllKeys(key);

            if (keys != null && keys.Count > 0)
            {
                updateinfo = Session.Current.Get <RecipesInfo>(keys[0]);
            }
            if (updateinfo != null)
            {
                updateinfo.Enable = enable;
                //移除之前的
                Session.Current.Remove(keys[0]);
                result = Session.Current.Set(updateinfo.GetKeyName(), updateinfo);
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据食谱编号获取缓存
        /// </summary>
        /// <param name="recipesId"></param>
        /// <returns></returns>
        public RecipesInfo GetRecipesInfoById(int recipesId)
        {
            string key = string.Format("DB_RI_{0}_*", recipesId);

            RecipesInfo    result = null;
            IList <string> keys   = Session.Current.ScanAllKeys(key);

            if (keys != null && keys.Count > 0)
            {
                result = Session.Current.Get <RecipesInfo>(keys[0]);
            }
            if (result == null)
            {
                //从数据库获取数据
                IList <RecipesInfo> recipeslist = DBConnectionManager.Instance.Reader.Select <RecipesInfo>(new RecipesSelectSpefication(recipesId.ToString(), 0).Satifasy());

                if (recipeslist != null && recipeslist.Count > 0)
                {
                    //更新缓存
                    result = recipeslist[0];
                    Session.Current.Set(result.GetKeyName(), result);
                    Session.Current.Expire(result.GetKeyName(), ExpireTime);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更新食谱信息
        /// </summary>
        /// <param name="recipes"></param>
        /// <returns></returns>
        public Result UpdateRecipes(Recipes recipes)
        {
            Result result = new Result()
            {
                Status  = true,
                Message = "删除食谱成功"
            };

            try
            {
                //食谱缓存服务
                IRecipesCache recipesservice = ServiceObjectContainer.Get <IRecipesCache>();

                RecipesInfo info = recipes.Copy <RecipesInfo>();
                if (info == null)
                {
                    throw new ArgumentNullException("更新食谱,参数非法");
                }

                info.UpdateDate = DateTime.Now;

                result.Status = DBConnectionManager.Instance.Writer.Update(new RecipesUpdateSpefication(info).Satifasy());

                if (!result.Status)
                {
                    DBConnectionManager.Instance.Writer.Rollback();
                    result.Status  = false;
                    result.Message = "更新食谱失败,请确保请求数据合法";
                }
                else
                {
                    DBConnectionManager.Instance.Writer.Commit();
                    //更新缓存
                    recipesservice.SaveInfo(info);
                }
            }
            catch (Exception ex)
            {
                DBConnectionManager.Instance.Writer.Rollback();
                result.Status  = false;
                result.Message = "删除食谱出错:" + ex.Message;
                LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:UpdateRecipes() .RecipesService"), LogType.ErrorLog);
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据手机号获取喜爱的食谱集
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        IList <RecipesInfo> IRecipesCache.GetRecipesInfoById(IList <int> recipesIds)
        {
            IList <RecipesInfo> result = null;

            if (recipesIds != null && recipesIds.Count > 0)
            {
                result = new List <RecipesInfo>();
                foreach (int id in recipesIds)
                {
                    RecipesInfo model = GetRecipesInfoById(id);
                    if (model != null)
                    {
                        result.Add(model);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 创建一个食谱
        /// </summary>
        /// <param name="recipes"></param>
        /// <returns></returns>
        public Result CreatRecipes(Recipes recipes)
        {
            Result result = new Result()
            {
                Status  = true,
                Message = "创建食谱成功"
            };

            try
            {
                //食谱缓存服务
                IRecipesCache recipesservice = ServiceObjectContainer.Get <IRecipesCache>();

                RecipesInfo addinfo = recipes.Copy <RecipesInfo>();
                if (addinfo == null)
                {
                    throw new ArgumentNullException("新增食谱信息,参数不能为空");
                }

                result.Status = DBConnectionManager.Instance.Writer.Insert(new RecipesAddSpefication(addinfo).Satifasy());

                if (result.Status)
                {
                    DBConnectionManager.Instance.Writer.Commit();
                    //更新缓存
                    recipesservice.SaveInfo(addinfo);
                }
                else
                {
                    DBConnectionManager.Instance.Writer.Rollback();
                }
            }
            catch (Exception ex)
            {
                DBConnectionManager.Instance.Writer.Rollback();
                result.Status  = false;
                result.Message = "创建食谱出错:" + ex.Message;
                LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:CreatRecipes() .RecipesService"), LogType.ErrorLog);
            }

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 根据食谱编号获取单个食谱信息
        /// </summary>
        /// <param name="recipesId"></param>
        /// <returns></returns>
        public Result <Recipes> GetRecipesById(int recipesId)
        {
            Result <Recipes> result = new Result <Recipes>()
            {
                Status  = true,
                Message = "查找食谱成功"
            };

            try
            {
                if (recipesId == 0)
                {
                    throw new ArgumentException("获取食谱,参数非法");
                }
                //食谱缓存服务
                IRecipesCache recipesservice = ServiceObjectContainer.Get <IRecipesCache>();

                RecipesInfo recipe = recipesservice.GetRecipesInfoById(recipesId);

                if (recipe != null)
                {
                    result.Data = recipe.Copy <Recipes>();
                }
                else
                {
                    result.Status  = false;
                    result.Message = "获取食谱失败,未找到对应食谱";
                }
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = "查找食谱出错:" + ex.Message;
                LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:GetRecipesById() .RecipesService"), LogType.ErrorLog);
            }


            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 设置食谱禁用(设置当前用户全部食谱)
        /// </summary>
        /// <param name="phone"></param>
        public void SetRecipesEnable(long phone, bool enable)
        {
            if (phone == 0)
            {
                throw new ArgumentNullException("phone can not be zero");
            }
            string         key  = string.Format("DB_RI_*_{0}", phone);
            IList <string> keys = Session.Current.ScanAllKeys(key);

            if (keys != null && keys.Count > 0)
            {
                RecipesInfo updateinfo = null;
                for (int i = 0; i < keys.Count; i++)
                {
                    updateinfo = Session.Current.Get <RecipesInfo>(keys[i]);
                }
                if (updateinfo != null)
                {
                    updateinfo.Enable = enable;
                    Session.Current.Set(updateinfo.GetKeyName(), updateinfo);
                }
            }
        }
Ejemplo n.º 8
0
 public RecipesAddSpefication(RecipesInfo recipes)
 {
     _info = recipes;
 }
Ejemplo n.º 9
0
        /// <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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
 public RecipesUpdateSpefication(RecipesInfo recipes)
 {
     _info = recipes;
 }