Пример #1
0
        /// <summary>
        /// 更新门店信息
        /// </summary>
        /// <param name="shopInfo">门店信息</param>
        /// <returns>操作结果</returns>
        public Result UpdateShopInfo(Shop shopInfo)
        {
            Result result = new Result()
            {
                Status  = true,
                Message = "更新门店成功"
            };

            try
            {
                bool cannext = false;

                ShopInfo info = shopInfo.Copy <ShopInfo>();
                if (info == null)
                {
                    throw new ArgumentNullException("更新门店,参数不能为空");
                }

                IShopCache shopservice = ServiceObjectContainer.Get <IShopCache>();
                IDishCache dishservice = ServiceObjectContainer.Get <IDishCache>();

                info.UpdateDate = DateTime.Now;
                //更新门店信息
                cannext = DBConnectionManager.Instance.Writer.Update(new ShopUpdateSpefication(info).Satifasy());
                //门店信息更新成功,更新关联食物的门店名称
                if (cannext)
                {
                    cannext = false;
                    cannext = DBConnectionManager.Instance.Writer.Update(new DishShopNameUpdateSpefication(info.ShopId, info.ShopName).Satifasy());
                }
                result.Status = cannext;

                if (!cannext)
                {
                    DBConnectionManager.Instance.Writer.Rollback();
                    result.Message = "更新门店失败,请确认参数合法";
                }
                else
                {
                    DBConnectionManager.Instance.Writer.Commit();
                    //同步缓存
                    shopservice.SaveInfo(info);
                    dishservice.UpdateDishInfoByChangeShopName(shopInfo.ShopId, shopInfo.ShopName);
                }
            }
            catch (Exception ex)
            {
                DBConnectionManager.Instance.Writer.Rollback();
                result.Status  = false;
                result.Message = "更新门店出错:" + ex.Message;
                LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:UpdateShopInfo() .ShopService"), LogType.ErrorLog);
            }

            return(result);
        }