예제 #1
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);
        }
예제 #2
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);
        }