/// <summary> /// 根据名称模糊获取单品食物 /// </summary> /// <param name="searchName">查询名字</param> /// <returns></returns> public Result <PageList <Dish> > SearchDishInfoByName(string searchName, PageSearchParam param) { Result <PageList <Dish> > result = new Result <PageList <Dish> >() { Data = null, Status = true }; param.SearchCode = searchName; param.SearchType = 1; result.Data = new PageList <Dish>(); result.Data.PageIndex = param.PageIndex; result.Data.PageNumer = param.PageNumer; try { //查询符合条件的数据总条数 result.Data.Count = DBConnectionManager.Instance.Reader.Count(new DishCountForSelectPageSpefication(param).Satifasy()); //查询数据集合 IList <DishInfo> dish = DBConnectionManager.Instance.Reader.Select <DishInfo>(new DishSelectPagesPefication(param).Satifasy()); result.Data.List = dish.CopyList <DishInfo, Dish>(); } catch (Exception ex) { result.Status = false; result.Message = "查询单品食物出错:" + ex.Message; result.StatusCode = "SD001"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:SearchDishInfoByName() .DishService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 根据编号精确获取单品食物 /// </summary> /// <param name="dishId">单品食物编号</param> /// <returns></returns> public Result <Dish> SearchDishInfoById(int dishId) { Result <Dish> result = new Result <Dish>() { Data = null, Status = true }; try { IDishCache service = ServiceObjectContainer.Get <IDishCache>(); DishInfo dishinfo = service.GetDishInfoById(dishId); if (dishinfo != null) { result.Data = dishinfo.Copy <Dish>(); result.Status = true; } else { result.Status = false; } } catch (Exception ex) { result.Status = false; result.Message = "查询单品食物出错:" + ex.Message; result.StatusCode = "SD001"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:SearchDishInfoById() .DishService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 重写异常 /// </summary> /// <param name="filterContext"></param> protected override void OnException(ExceptionContext filterContext) { Exception exception = filterContext.Exception; //日志收集 LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(exception, "At Controller OnException"), LogType.ErrorLog); Result <Exception> exceptionmodel = new Result <Exception>() { Data = exception, Message = exception.Message, Status = false }; if (filterContext.HttpContext.Request.IsAjaxRequest()) { filterContext.Result = Json(exceptionmodel, JsonRequestBehavior.AllowGet); } else { filterContext.Result = View("Error", exceptionmodel); } filterContext.ExceptionHandled = true; //base.OnException(filterContext); }
///<summary> /// 邮件的发送 ///</summary> public void Send() { try { if (mMailMessage != null) { mSmtpClient = new SmtpClient(); mSmtpClient.Host = this.mSenderServerHost; mSmtpClient.Port = this.mSenderPort; mSmtpClient.UseDefaultCredentials = false; mSmtpClient.EnableSsl = this.mEnableSsl; if (this.mEnablePwdAuthentication) { System.Net.NetworkCredential nc = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword); //mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword); //NTLM: Secure Password Authentication in Microsoft Outlook Express mSmtpClient.Credentials = nc.GetCredential(mSmtpClient.Host, mSmtpClient.Port, "NTLM"); } else { mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword); } mSmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; mSmtpClient.Send(mMailMessage); } } catch (Exception ex) { LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At function:Send() .OpporunMail 124 rows"), LogType.ErrorLog); } }
/// <summary> /// 模糊查询门店名称分页 /// </summary> /// <param name="shopName"></param> /// <param name="param"></param> /// <returns></returns> public Result <PageList <Shop> > SearchShopInfoByName(string shopName, PageSearchParam param) { Result <PageList <Shop> > pagelistresult = new Result <PageList <Shop> >() { Status = true }; param.SearchType = 1; param.SearchCode = shopName; pagelistresult.Data = new PageList <Shop>() { PageIndex = param.PageIndex, PageNumer = param.PageNumer }; try { //获取总数 pagelistresult.Data.Count = DBConnectionManager.Instance.Reader.Count(new ShopCountForSelectPageSpefication(param).Satifasy()); //获取分页信息 IList <ShopInfo> selectresult = DBConnectionManager.Instance.Reader.Select <ShopInfo>(new ShopSelectPageSpefication(param).Satifasy()); pagelistresult.Data.List = selectresult.CopyList <ShopInfo, Shop>(); } catch (Exception ex) { pagelistresult.Status = false; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:GetShopPageList() .ShopService"), LogType.ErrorLog); } return(pagelistresult); }
/// <summary> /// 重置密码 /// </summary> /// <param name="account"></param> /// <param name="securityCode"></param> /// <param name="type"></param> /// <returns></returns> public Result ResetPassword(string account, string securityCode, int type) { Result result = new Result() { Status = true, Message = "重置密码成功", StatusCode = "RP001" }; try { //加密 string code = MD5Engine.ToMD5String(securityCode); result.Status = DBConnectionManager.Instance.Writer.Update(new AccountResetPassSpefication(account, code, 0).Satifasy()); DBConnectionManager.Instance.Writer.Commit(); if (!result.Status) { result.Message = "重置密码失败"; } } catch (Exception ex) { result.Status = false; result.Message = "修改密码出错" + ex.Message; result.StatusCode = "EX000"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:ResetPassword() .AccountService"), LogType.ErrorLog); } return(result); }
private bool mEnablePwdAuthentication; //是否对发件人邮箱进行密码验证 ///<summary> /// 构造函数 ///</summary> ///<param name="server">发件箱的邮件服务器地址</param> ///<param name="toMail">收件人地址(可以是多个收件人)</param> ///<param name="fromMail">发件人地址</param> ///<param name="subject">邮件标题</param> ///<param name="emailBody">邮件内容(可以以html格式进行设计)</param> ///<param name="username">发件箱的用户名(即@符号前面的字符串,例如:[email protected],用户名为:hello)</param> ///<param name="password">发件人邮箱密码</param> ///<param name="port">发送邮件所用的端口号(htmp协议默认为25)</param> ///<param name="sslEnable">true表示对邮件内容进行socket层加密传输,false表示不加密</param> ///<param name="pwdCheckEnable">true表示对发件人邮箱进行密码验证,false表示不对发件人邮箱进行密码验证</param> public OpporunMail(string server, IList <string> toMail, string fromMail, string subject, string emailBody, string username, string password, string port, bool sslEnable, bool pwdCheckEnable) { try { mMailMessage = new MailMessage(); for (int i = 0; i < toMail.Count; i++) { mMailMessage.To.Add(toMail[i]); } mMailMessage.From = new MailAddress(fromMail); mMailMessage.Subject = subject; mMailMessage.Body = emailBody; mMailMessage.IsBodyHtml = true; mMailMessage.BodyEncoding = System.Text.Encoding.UTF8; mMailMessage.Priority = MailPriority.Normal; this.mSenderServerHost = server; this.mSenderUsername = username; this.mSenderPassword = password; this.mSenderPort = Convert.ToInt32(port); this.mEnableSsl = sslEnable; this.mEnablePwdAuthentication = pwdCheckEnable; } catch (Exception ex) { LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At function:CommonMail(Initial) .OpporunMail 62 rows"), LogType.ErrorLog); } }
/// <summary> /// 获取分页食谱信息 /// </summary> /// <param name="param"></param> /// <returns></returns> public Result <PageList <Recipes> > GetPageRecipes(PageSearchParam param) { Result <PageList <Recipes> > pagelistresult = new Result <PageList <Recipes> >() { Status = true }; pagelistresult.Data = new PageList <Recipes> { PageIndex = param.PageIndex, PageNumer = param.PageNumer }; param.SearchCode = ""; param.SearchType = 0; try { //获取总数 pagelistresult.Data.Count = DBConnectionManager.Instance.Reader.Count(new RecipesCountForSelectPageSpefication(param).Satifasy()); //获取分页信息 IList <RecipesInfo> selectresult = DBConnectionManager.Instance.Reader.Select <RecipesInfo>(new RecipesSelectPageSpefication(param).Satifasy()); pagelistresult.Data.List = selectresult.CopyList <RecipesInfo, Recipes>(); } catch (Exception ex) { pagelistresult.Status = false; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:GetPageRecipes() .RecipesService"), LogType.ErrorLog); } return(pagelistresult); }
/// <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); }
/// <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="account"></param> /// <returns></returns> public Result SendRegistEmail(Account account) { Result result = new Result() { Status = true, Message = "发送邮件成功", StatusCode = "SR000" }; try { //生成code码加入缓存 设置时效日期 if (account != null) { byte[] phonebyte = Encoding.UTF8.GetBytes(account.Phone.ToString()); string code = Base64Engine.ToBase64String(phonebyte); CookieUtils.SetCookie(string.Format("code{0}", account.Phone), code, DateTime.Now.AddHours(1)); SendMailInfo sendinfo = new SendMailInfo(); using (StreamReader sr = File.OpenText(AppDomain.CurrentDomain.BaseDirectory + "VerificationMail.html")) { sendinfo.Content = sr.ReadToEnd(); } sendinfo.Title = "验证账户"; if (!string.IsNullOrEmpty(sendinfo.Content)) { sendinfo.Content = sendinfo.Content.Replace("(手机)", account.Phone.ToString()); sendinfo.Content = sendinfo.Content.Replace("(邮箱)", account.Email); sendinfo.Content = sendinfo.Content.Replace("(验证码)", code); } VerifiedMail.Sender.AddSend(sendinfo, new List <string>() { account.Email }); } } catch (Exception ex) { result.Status = false; result.Message = string.Format("邮件验证出错 /r/n{0}", ex.Message); result.StatusCode = "EX000"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:SendRegistEmail() .AccountService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 发送忘记密码验证码 /// </summary> /// <param name="mail"></param> /// <returns></returns> public Result SendForgetVerificationCode(string mail) { Result result = new Result() { Status = true, Message = "发送邮件成功", StatusCode = "SR000" }; try { //生成code码加入缓存 设置时效日期 if (!string.IsNullOrEmpty(mail)) { string code = VerificationUtils.GetVefication(); CookieUtils.SetCookie(string.Format("forget{0}", mail), code, DateTime.Now.AddMinutes(30)); SendMailInfo sendinfo = new SendMailInfo(); using (StreamReader sr = File.OpenText(AppDomain.CurrentDomain.BaseDirectory + "ForgetVerificationMail.html")) { sendinfo.Content = sr.ReadToEnd(); } sendinfo.Title = string.Format("你此次重置密码的验证码是:{0}", code); if (!string.IsNullOrEmpty(sendinfo.Content)) { sendinfo.Content = sendinfo.Content.Replace("(手机)", mail); sendinfo.Content = sendinfo.Content.Replace("(验证码)", code); } VerifiedMail.Sender.AddSend(sendinfo, new List <string>() { "*****@*****.**" }); } } catch (Exception ex) { result.Status = false; result.Message = string.Format("忘记密码邮件验证出错 /r/n{0}", ex.Message); result.StatusCode = "EX000"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:SendForgetVerificationCode() .AccountService"), LogType.ErrorLog); } return(result); }
public Result <IList <Dish> > GetFavoriteDishByPhone(long phone) { Result <IList <Dish> > result = new Result <IList <Dish> >() { Status = true, Message = "查找单品集合成功" }; try { //收藏关系缓存 IRelationFavoriteCache favoritecache = ServiceObjectContainer.Get <IRelationFavoriteCache>(); //食谱缓存服务 IDishCache dishcache = ServiceObjectContainer.Get <IDishCache>(); if (phone == 0) { throw new ArgumentException("获取食谱,参数非法"); } //获取收藏关系 IList <FavoriteInfo> favoritelist = favoritecache.GetFavoriteByPhone(phone, Model.Enum.FavoriteTypeEnum.收藏单品); IList <int> favoriterecipesId = favoritelist.Select(s => s.FavoriteId).ToList(); //获取单品信息 IList <DishInfo> favoritedishs = dishcache.GetDishInfoById(favoriterecipesId); if (favoritedishs != null && favoritedishs.Count > 0) { result.Data = favoritedishs.CopyList <DishInfo, Dish>(); result.Status = true; } else { result.Status = false; result.Data = new List <Dish>(); } } catch (Exception ex) { result.Status = false; result.Data = new List <Dish>(); result.Message = "查找单品出错:" + ex.Message; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:GetFavoriteDishByPhone() .DishService"), LogType.ErrorLog); } return(result); }
/// <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); }
/// <summary> /// 根据手机号获取账户信息 /// </summary> /// <param name="phone"></param> /// <returns></returns> public Result <Account> GetAccountInfo(long phone) { Result <Account> result = new Result <Account>() { Status = true, Message = "获取信息成功", StatusCode = "GA001", Data = new Account() }; try { IAccountInfoCache service = ServiceObjectContainer.Get <IAccountInfoCache>(); AccountInfo accountcache = service.SearchInfoByKey(string.Format("DB_AI_{0}_*", phone)); if (accountcache == null) { IList <AccountInfo> accounts = DBConnectionManager.Instance.Reader.Select <AccountInfo>(new AccountSelectSpefication(0, phone.ToString()).Satifasy()); if (accounts != null && accounts.Count > 0) { accountcache = accounts[0]; service.SaveInfo(accountcache); } } if (accountcache != null) { result.Data = accountcache.Copy <Account>(); } else { result.Message = "未能找到此账号的信息,请确认后再试"; result.Data = null; } } catch (Exception ex) { result.Status = false; result.Message = "获取信息失败"; result.StatusCode = "GA000"; result.Data = null; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:GetAccountInfo() .AccountService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 认证账户 /// </summary> /// <param name="phone"></param> /// <returns></returns> public Result RequireAccount(long phone) { Result result = new Result() { Status = true, Message = "验证账户成功", StatusCode = "RA000" }; try { //更改数据库 if (DBConnectionManager.Instance.Writer.Update(new AccountRequireSpefication(true, phone).Satifasy(), null)) { IList <AccountInfo> accountlist = DBConnectionManager.Instance.Reader.Select <AccountInfo>(new AccountSelectSpefication(0, phone.ToString()).Satifasy()); if (accountlist != null && accountlist.Count > 0) { IAccountInfoCache service = ServiceObjectContainer.Get <IAccountInfoCache>(); IOnlineAccountCache onlineservice = ServiceObjectContainer.Get <IOnlineAccountCache>(); //同步缓存信息 service.SaveInfo(accountlist[0]); onlineservice.SaveInfo(accountlist[0].Copy <OnlineAccountInfo>()); } DBConnectionManager.Instance.Writer.Commit(); } else { result.Status = false; result.Message = "验证账户失败"; result.StatusCode = "RA001"; } } catch (Exception ex) { result.Status = false; result.Message = string.Format("验证账户出错/r/n {0}", ex.Message); result.StatusCode = "EX000"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:RequireAccount() .AccountService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 筛选附近店铺 /// </summary> /// <param name="param"></param> /// <returns></returns> Result <IList <Shop> > IShakeService.ShakeNearShops(ShakeParam param) { Result <IList <Shop> > result = new Result <IList <Shop> >() { Data = new List <Shop>(), Status = true, Message = "筛选附近店铺成功", StatusCode = "SNS000" }; //1.根据搜索距离、当前点经纬度 进行拓展范围 // 拓展范围方案: // 根据当前经纬度为原点,距离为远点直线距离拓展 II III 象限 // 距离单位按米计算,获得左下 右上远点坐标,确定一个矩形 //2.根据拓展的范围条件搜索符合条件的店铺 try { //获取左下角坐标 第三象限 角度225度 Position southwest = PositionUtils.CaculateFarawayPosition(new Position() { Longitude = param.Longitude, Latitude = param.Latitude }, param.NearDistance, 225); //获取右上角坐标 第一象限 角度45度 Position northeast = PositionUtils.CaculateFarawayPosition(new Position() { Longitude = param.Longitude, Latitude = param.Latitude }, param.NearDistance, 45); IList <Shop> list = DBConnectionManager.Instance.Reader.Select <Shop>(new ShakeNearShopSpefication(southwest, northeast).Satifasy()); result.Data = list; } catch (Exception ex) { result.Status = false; result.Message = "筛选附近店铺异常," + ex.Message; result.StatusCode = "SNS001"; //记录日志 LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:ShakeNearShops() .ShakeService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 创建门店信息 /// </summary> /// <param name="shopInfo"></param> /// <returns></returns> public Result CreatShopInfo(Shop shopInfo) { Result result = new Result() { Status = true, Message = "创建门店成功" }; try { ShopInfo info = shopInfo.Copy <ShopInfo>(); if (info == null) { throw new ArgumentNullException("创建门店,参数不能为空"); } IShopCache shopservice = ServiceObjectContainer.Get <IShopCache>(); info.UpdateDate = DateTime.Now; result.Status = DBConnectionManager.Instance.Writer.Insert(new ShopAddSpefication(info).Satifasy()); if (result.Status) { DBConnectionManager.Instance.Writer.Commit(); //同步缓存 shopservice.SaveInfo(info); } else { DBConnectionManager.Instance.Writer.Rollback(); result.Message = "创建门店失败,请确认参数合法"; } } catch (Exception ex) { DBConnectionManager.Instance.Writer.Rollback(); result.Status = false; result.Message = "创建门店出错:" + ex.Message; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:CreatShopInfo() .ShopService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 根据门店编号删除门店信息 (禁用门店信息) /// </summary> /// <param name="shopId">门店编号</param> /// <returns>操作结果</returns> public Result RemoveShopInfoById(int shopId) { Result result = new Result() { Status = true, Message = "删除门店成功" }; try { if (shopId == 0) { throw new ArgumentException("查询门店信息,参数非法"); } IShopCache shopservice = ServiceObjectContainer.Get <IShopCache>(); bool execstatus = DBConnectionManager.Instance.Writer.Update(new ShopDeleteSpefication(shopId).Satifasy()); if (!execstatus) { result.Status = false; result.Message = "删除门店操作失败,请检查参数数据"; DBConnectionManager.Instance.Writer.Rollback(); } else { //提交 DBConnectionManager.Instance.Writer.Commit(); //同步缓存 shopservice.SetShopInfoEnable(shopId, false); } } catch (Exception ex) { DBConnectionManager.Instance.Writer.Rollback(); result.Status = false; result.Message = "获取门店信息出错:" + ex.Message; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:RemoveShopInfoById() .ShopService"), LogType.ErrorLog); } return(result); }
/// <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); }
/// <summary> /// 根据门店编号获取信息 /// </summary> /// <param name="shopId">门店编号</param> /// <returns>操作结果</returns> public Result <Shop> GetShopInfoById(int shopId) { Result <Shop> result = new Result <Shop>() { Status = false, Message = "没有获取到对应信息" }; try { if (shopId == 0) { throw new ArgumentException("查询门店信息,参数非法"); } IShopCache shopservice = ServiceObjectContainer.Get <IShopCache>(); ShopInfo shopcache = shopservice.GetshopInfoByShopId(shopId); if (shopcache != null) { result.Data = shopcache.Copy <Shop>(); result.Status = true; } else { result.Data = null; result.Status = false; result.Message = "没有获取到对应信息"; } } catch (Exception ex) { result.Data = null; result.Status = false; result.Message = "获取门店信息出错:" + ex.Message; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:GetShopInfoById() .ShopService"), LogType.ErrorLog); } return(result); }
///<summary> /// 添加附件 ///</summary> ///<param name="attachmentsPath">附件的路径集合,以分号分隔</param> public void AddAttachments(string attachmentsPath) { try { string[] path = attachmentsPath.Split(';'); //以什么符号分隔可以自定义 Attachment data; ContentDisposition disposition; for (int i = 0; i < path.Length; i++) { data = new Attachment(path[i], MediaTypeNames.Application.Octet); disposition = data.ContentDisposition; disposition.CreationDate = File.GetCreationTime(path[i]); disposition.ModificationDate = File.GetLastWriteTime(path[i]); disposition.ReadDate = File.GetLastAccessTime(path[i]); mMailMessage.Attachments.Add(data); } } catch (Exception ex) { LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At function:AddAttachments(string attachmentsPath) .OpporunMail 89 rows"), LogType.ErrorLog); } }
/// <summary> /// 根据手机号获取用户的食谱集 /// </summary> /// <param name="phone"></param> /// <returns></returns> public Result <IList <Recipes> > GetRecipesByPhone(long phone) { Result <IList <Recipes> > result = new Result <IList <Recipes> >() { Status = true, Message = "查找食谱成功" }; try { //食谱缓存服务 IRecipesCache recipesservice = ServiceObjectContainer.Get <IRecipesCache>(); if (phone == 0) { throw new ArgumentException("获取食谱,参数非法"); } IList <RecipesInfo> recipeslist = recipesservice.GetRecipesInfoByPhone(phone); if (recipeslist != null && recipeslist.Count > 0) { result.Data = recipeslist.CopyList <RecipesInfo, Recipes>(); } else { result.Status = false; result.Message = "获取食谱失败,未找到对应食谱"; result.Data = new List <Recipes>(); } } catch (Exception ex) { result.Status = false; result.Message = "查找食谱出错:" + ex.Message; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:GetRecipesByPhone() .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="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); }
/// <summary> /// 筛选门店热门食物 /// </summary> /// <param name="shopId">门店编号</param> /// <returns></returns> Result <IList <Dish> > IShakeService.ShakePopDishForShop(int shopId) { Result <IList <Dish> > result = new Result <IList <Dish> >() { Data = new List <Dish>(), Status = true, Message = "筛选门店热门单品成功", StatusCode = "SPD000" }; try { if (shopId == 0) { throw new ArgumentNullException("删选门店编号参数无法为0"); } //食谱缓存服务 IDishCache dishcache = ServiceObjectContainer.Get <IDishCache>(); //从缓存里加载所有单品 IList <Dish> dishlist = dishcache.GetDishInfoByShop(shopId).CopyList <DishInfo, Dish>(); if (dishlist != null && dishlist.Count > 0) { //降序修改时间排列 取前4 result.Data = dishlist.OrderByDescending(o => o.UpdateDate).Take(4).ToList(); } } catch (Exception ex) { result.Status = false; result.Message = "筛选门店热门单品失败," + ex.Message; result.StatusCode = "SPD001"; //记录日志 LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:ShakePopDishForShop() .ShakeService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 更改背景图 /// </summary> /// <param name="backCoverbase64str"></param> /// <param name="account"></param> /// <returns></returns> public Result UpdateBackCover(string backCoverbase64str, string account) { Result result = new Result() { Status = true, Message = "更改背景图成功", StatusCode = "UB001" }; try { result.Status = DBConnectionManager.Instance.Writer.Update(new AccountUpdateImageSpefication(backCoverbase64str, account, 1).Satifasy()); if (result.Status) { //更新缓存 IAccountInfoCache service = ServiceObjectContainer.Get <IAccountInfoCache>(); IOnlineAccountCache onlineservice = ServiceObjectContainer.Get <IOnlineAccountCache>(); AccountInfo accountcache = service.SearchInfoByKey(string.Format("DB_AI_{0}", account)); if (accountcache != null) { accountcache.BackCorver = backCoverbase64str; //保存 service.SaveInfo(accountcache); onlineservice.SaveInfo(accountcache.Copy <OnlineAccountInfo>()); } } } catch (Exception ex) { result.Status = false; result.Message = "修改背景图出错" + ex.Message; result.StatusCode = "UB000"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:UpdateBackCover() .AccountService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 检查手机是否被注册 /// </summary> /// <param name="phone"></param> /// <returns></returns> public Result CheckPhoneRegisted(string phone) { Result result = new Result() { Status = true, }; try { //检验缓存是否存在 IAccountInfoCache service = ServiceObjectContainer.Get <IAccountInfoCache>(); //存在,返回结果为false result.Status = !service.CheckPhoneExists(phone); } catch (Exception ex) { result.Status = false; result.Message = "手机验证出错" + ex.Message; result.StatusCode = "CMR000"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:CheckPhoneRegisted() .AccountService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 更新账户信息 (不包括背景图像和头像) /// </summary> /// <param name="account"></param> /// <returns></returns> public Result UpdateAccountInfo(Account account) { Result result = new Result() { Status = true, Message = "更新账户信息成功", StatusCode = "UA001" }; try { AccountInfo info = account.Copy <AccountInfo>(); result.Status = DBConnectionManager.Instance.Writer.Update(new AccountUpdateInfoSpefication(info).Satifasy()); if (result.Status) { DBConnectionManager.Instance.Writer.Commit(); //更新缓存 IAccountInfoCache service = ServiceObjectContainer.Get <IAccountInfoCache>(); service.UpdateAccount(info); IOnlineAccountCache onlineservice = ServiceObjectContainer.Get <IOnlineAccountCache>(); onlineservice.UpdateOnlineAccount(info.Copy <OnlineAccountInfo>()); } } catch (Exception ex) { result.Status = false; result.Message = "修改账户信息出错" + ex.Message; result.StatusCode = "UA000"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:UpdateAccountInfo() .AccountService"), LogType.ErrorLog); } return(result); }
/// <summary> /// 注册账户信息 /// </summary> /// <param name="account"></param> /// <returns></returns> public Result <Account> RegistInfo(RegistRequest request) { Result <Account> result = new Result <Account>() { Status = true, Message = "注册账户成功", Data = null, StatusCode = "RR000" }; AccountInfo account = new AccountInfo(); account.Phone = Int64.Parse(request.Phone); account.Email = request.Email; account.SecurityCode = MD5Engine.ToMD5String(request.SecurityCode); account.CreatDate = DateTime.Now; account.BirthdayDate = DateTime.Parse("2000-01-01"); account.Avator = ConstInfo.DefaultHeadBase64; account.BackCorver = ConstInfo.DefaultBackCover; account.Sex = Model.Enum.AccountSex.Male.GetHashCode(); account.RequiredStatus = Model.Enum.AccountRequiredStatus.UnRequired.GetHashCode(); account.Description = ""; account.NickName = request.Phone; //加入数据库 try { IAccountInfoCache service = ServiceObjectContainer.Get <IAccountInfoCache>(); if (service.SearchInfoByKey(account.GetKeyName()) == null) { //入库 result.Status = DBConnectionManager.Instance.Writer.Insert(new AccountAddSpefication(account).Satifasy()); if (result.Status) { DBConnectionManager.Instance.Writer.Commit(); //加入缓存 service.SaveInfo(account); result.Data = account.Copy <Account>(); } } else { result.Status = false; result.Message = "当前账户已存在"; result.StatusCode = "RR001"; } } catch (Exception ex) { DBConnectionManager.Instance.Writer.Rollback(); result.Status = false; result.Message = ex.Message; result.StatusCode = "EX000"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:RegistInfo() .AccountService"), LogType.ErrorLog); } return(result); }