//查询方法 private List <Data_BillInfo> Search(string title = null, string publishDate = null) { //为了模拟EF查询,转换为IEnumerable,在EF中此处为数据库上下文的表对象 IData_BillInfoService data_BillInfoService = BLLContainer.Resolve <IData_BillInfoService>(); var result = data_BillInfoService.GetModels(); /*下列代码不会立即执行查询,而是生成查询计划 * 若参数不存在则不添加查询条件,从而可以无限制的添加查询条件 */ if (!string.IsNullOrEmpty(title)) { result = result.Where(p => p.Title.Contains(title)); } if (!string.IsNullOrEmpty(publishDate)) { var date = Convert.ToDateTime(publishDate); result = result.Where(p => System.Data.Entity.DbFunctions.DiffDays(p.ReleaseTime, date) == 0); } //此时执行查询 var final = result.ToList(); return(final); }
public object DeletePicture(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string fileName = dicParas.ContainsKey("fileName") ? dicParas["fileName"].ToString() : string.Empty; if (fileName == null) { errMsg = "图片名称不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } string picturePath = System.Configuration.ConfigurationManager.AppSettings["UploadImageUrl"].ToString() + "/XCCloud/"; string path = System.Web.HttpContext.Current.Server.MapPath(picturePath); IData_BillInfoService data_BillInfoService = BLLContainer.Resolve <IData_BillInfoService>(); SqlParameter[] parameters = new SqlParameter[1]; parameters[0] = new SqlParameter("@PicturePath", picturePath + fileName); data_BillInfoService.ExecuteSqlCommand("update Data_BillInfo set PicturePath='' where PicturePath=@PicturePath", parameters); if (File.Exists(path + fileName)) { File.Delete(path + fileName); } return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn)); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }
public object DeleteBill(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string id = dicParas.ContainsKey("id") ? dicParas["id"].ToString() : string.Empty; #region 验证参数 if (string.IsNullOrEmpty(id)) { errMsg = "ID不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(id)) { errMsg = "ID须为整形"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } #endregion IData_BillInfoService data_BillInfoService = BLLContainer.Resolve <IData_BillInfoService>(); int iId = Convert.ToInt32(id); if (!data_BillInfoService.Any(p => p.ID.Equals(iId))) { errMsg = "该海报Id不存在"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } var data_BillInfoModel = data_BillInfoService.GetModels(p => p.ID.Equals(iId)).FirstOrDefault <Data_BillInfo>(); if (!data_BillInfoService.Delete(data_BillInfoModel)) { errMsg = "删除海报失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (File.Exists(data_BillInfoModel.PicturePath)) { File.Delete(data_BillInfoModel.PicturePath); } return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn)); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }
public object GetPictures(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; IData_BillInfoService data_BillInfoService = BLLContainer.Resolve <IData_BillInfoService>(); string sql = "select * from Data_BillInfo"; var data_BillInfo = data_BillInfoService.SqlQuery(sql).ToList().GroupBy(p => p.PicturePath).Select(g => g.Key).ToList(); return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn, data_BillInfo)); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }
public object PublishBill(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string id = dicParas.ContainsKey("id") ? dicParas["id"].ToString() : string.Empty; string title = dicParas.ContainsKey("title") ? dicParas["title"].ToString() : string.Empty; string publishType = dicParas.ContainsKey("publishType") ? dicParas["publishType"].ToString() : string.Empty; string promotionType = dicParas.ContainsKey("promotionType") ? dicParas["promotionType"].ToString() : string.Empty; string picturePath = dicParas.ContainsKey("picturePath") ? dicParas["picturePath"].ToString() : string.Empty; string pagePath = dicParas.ContainsKey("pagePath") ? dicParas["pagePath"].ToString() : string.Empty; #region 验证参数 if (!string.IsNullOrEmpty(id) && !Utils.isNumber(id)) { errMsg = "海报ID格式不正确"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrEmpty(title)) { errMsg = "标题不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrEmpty(publishType)) { errMsg = "展示方式不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrEmpty(promotionType)) { errMsg = "活动类别不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrEmpty(pagePath)) { errMsg = "活动内容不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (title.Length > 50) { errMsg = "标题不能超过50字"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(publishType)) { errMsg = "展示方式须为整形"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(promotionType)) { errMsg = "活动类别须为整形"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } #endregion Data_BillInfo data_BillInfoModel = new Data_BillInfo(); IData_BillInfoService data_BillInfoService = BLLContainer.Resolve <IData_BillInfoService>(); if (!data_BillInfoService.Any(p => p.ID.ToString().Equals(id, StringComparison.OrdinalIgnoreCase))) { data_BillInfoModel.Title = title; data_BillInfoModel.PublishType = Convert.ToInt32(publishType); data_BillInfoModel.PromotionType = Convert.ToInt32(promotionType); data_BillInfoModel.PicturePath = picturePath; data_BillInfoModel.PagePath = pagePath; data_BillInfoModel.State = 1; data_BillInfoModel.Time = DateTime.Now; data_BillInfoModel.ReleaseTime = DateTime.Now; if (!data_BillInfoService.Add(data_BillInfoModel)) { errMsg = "发布海报失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } else { data_BillInfoModel = data_BillInfoService.GetModels(p => p.ID.ToString().Equals(id, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <Data_BillInfo>(); data_BillInfoModel.Title = title; data_BillInfoModel.PublishType = Convert.ToInt32(publishType); data_BillInfoModel.PromotionType = Convert.ToInt32(promotionType); data_BillInfoModel.PicturePath = picturePath; data_BillInfoModel.PagePath = pagePath; data_BillInfoModel.State = 1; data_BillInfoModel.ReleaseTime = DateTime.Now; if (!data_BillInfoService.Update(data_BillInfoModel)) { errMsg = "发布海报失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn)); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }