public ActionResult Details(string id) { ViewBag.Perm = GetPermission(); Spl_ProductModel entity = m_BLL.GetById(id); return(View(entity)); }
public virtual async Task <Spl_ProductModel> GetByIdAsync(object id) { if (IsExists(id)) { Spl_Product entity = await m_Rep.GetByIdAsync(id); Spl_ProductModel model = new Spl_ProductModel(); model.Id = entity.Id; model.Name = entity.Name; model.Code = entity.Code; model.Price = entity.Price; model.Color = entity.Color; model.Number = entity.Number; model.CategoryId = entity.CategoryId; model.CreateTime = entity.CreateTime; model.CreateBy = entity.CreateBy; model.CostPrice = entity.CostPrice; return(model); } else { return(null); } }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_ProductModel model) { ValidationErrors errors = new ValidationErrors(); try { Spl_Product entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new Spl_Product(); entity.Id = model.Id; entity.Name = model.Name; entity.Code = model.Code; entity.Price = model.Price; entity.Color = model.Color; entity.Number = model.Number; entity.CategoryId = model.CategoryId; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; entity.CostPrice = model.CostPrice; if (await m_Rep.CreateAsync(entity)) { return(new Tuple <ValidationErrors, bool>(errors, true)); } else { errors.Add(Resource.InsertFail); return(new Tuple <ValidationErrors, bool>(errors, false)); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(new Tuple <ValidationErrors, bool>(errors, false)); } }
public JsonResult Edit(Spl_ProductModel model) { if (model != null && ModelState.IsValid) { if (m_BLL.Edit(ref errors, model)) { LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "修改", "Spl_Product"); return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "修改", "Spl_Product"); return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol))); } } else { return(Json(JsonHandler.CreateMessage(0, Resource.EditFail))); } }
public virtual bool Create(ref ValidationErrors errors, Spl_ProductModel model) { try { Spl_Product entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new Spl_Product(); entity.Id = model.Id; entity.Name = model.Name; entity.Code = model.Code; entity.Price = model.Price; entity.CostPrice = model.CostPrice; entity.Color = model.Color; entity.Number = model.Number; entity.CategoryId = model.CategoryId; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual bool Edit(ref ValidationErrors errors, Spl_ProductModel model) { try { Spl_Product entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.Name = model.Name; entity.Code = model.Code; entity.Price = model.Price; entity.CostPrice = model.CostPrice; entity.Color = model.Color; entity.Number = model.Number; entity.CategoryId = model.CategoryId; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public JsonResult Create(Spl_ProductModel model) { model.Id = ResultHelper.NewId; model.CreateTime = ResultHelper.NowTime; if (model != null && ModelState.IsValid) { if (m_BLL.Create(ref errors, model)) { LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "创建", "Spl_Product"); return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "创建", "Spl_Product"); return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol))); } } else { return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail))); } }
public virtual Spl_ProductModel GetById(string id) { if (IsExists(id)) { Spl_Product entity = m_Rep.GetById(id); Spl_ProductModel model = new Spl_ProductModel(); model.Id = entity.Id; model.Name = entity.Name; model.Code = entity.Code; model.Price = entity.Price; model.Color = entity.Color; model.Number = entity.Number; model.CategoryId = entity.CategoryId; model.CreateTime = entity.CreateTime; model.CreateBy = entity.CreateBy; model.CostPrice = entity.CostPrice; return(model); } else { return(null); } }
public ActionResult Details(string id) { Spl_ProductModel entity = m_BLL.GetById(id); return(View(entity)); }
/// <summary> /// 校验Excel数据,这个方法一般用于重写校验逻辑 /// </summary> public virtual bool CheckImportData(string fileName, List <Spl_ProductModel> list, ref ValidationErrors errors) { var targetFile = new FileInfo(fileName); if (!targetFile.Exists) { errors.Add("导入的数据文件不存在"); return(false); } var excelFile = new ExcelQueryFactory(fileName); //对应列头 excelFile.AddMapping <Spl_ProductModel>(x => x.Name, "产品名称"); excelFile.AddMapping <Spl_ProductModel>(x => x.Code, "产品代码"); excelFile.AddMapping <Spl_ProductModel>(x => x.Price, "产品价格"); excelFile.AddMapping <Spl_ProductModel>(x => x.CostPrice, "CostPrice"); excelFile.AddMapping <Spl_ProductModel>(x => x.Color, "产品颜色"); excelFile.AddMapping <Spl_ProductModel>(x => x.Number, "产品数量"); excelFile.AddMapping <Spl_ProductModel>(x => x.CategoryId, "类别"); excelFile.AddMapping <Spl_ProductModel>(x => x.CreateTime, "CreateTime"); excelFile.AddMapping <Spl_ProductModel>(x => x.CreateBy, "CreateBy"); //SheetName var excelContent = excelFile.Worksheet <Spl_ProductModel>(0); int rowIndex = 1; //检查数据正确性 foreach (var row in excelContent) { var errorMessage = new StringBuilder(); var entity = new Spl_ProductModel(); entity.Id = row.Id; entity.Name = row.Name; entity.Code = row.Code; entity.Price = row.Price; entity.CostPrice = row.CostPrice; entity.Color = row.Color; entity.Number = row.Number; entity.CategoryId = row.CategoryId; entity.CreateTime = row.CreateTime; entity.CreateBy = row.CreateBy; //============================================================================= if (errorMessage.Length > 0) { errors.Add(string.Format( "第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); } list.Add(entity); rowIndex += 1; } if (errors.Count > 0) { return(false); } return(true); }
public ActionResult JsApi(string code, string state) { if (string.IsNullOrEmpty(code)) { return(Content("您拒绝了授权!")); } if (!state.Contains("|")) { //这里的state其实是会暴露给客户端的,验证能力很弱,这里只是演示一下 //实际上可以存任何想传递的数据,比如用户ID,并且需要结合例如下面的Session["OAuthAccessToken"]进行验证 return(Content("验证失败!请从正规途径进入!1001")); } //获取产品信息 var stateData = state.Split('|'); //商品 string Id = stateData[0]; Spl_ProductModel product = m_BLL.GetById(Id); if (product == null) { return(Content("商品信息不存在,或非法进入!1002")); } //todo 这里需要为用户保存订单 //todo 如果用户的订单已经存在,那么不需要再次添加,激活此订单 ViewData["product"] = product; //通过,用code换取access_token //-------------------开起来支付 var openIdResult = OAuthApi.GetAccessToken(TenPayV3Info.AppId, TenPayV3Info.AppSecret, code); if (openIdResult.errcode != ReturnCode.请求成功) { return(Content("错误:" + openIdResult.errmsg)); } string timeStamp = ""; string nonceStr = ""; string paySign = ""; //把系统ID当成订单号 string sp_billno = product.Id; //创建支付应答对象 RequestHandler packageReqHandler = new RequestHandler(null); //初始化 packageReqHandler.Init(); timeStamp = TenPayV3Util.GetTimestamp(); nonceStr = TenPayV3Util.GetNoncestr(); //设置package订单参数 packageReqHandler.SetParameter("appid", TenPayV3Info.AppId); //公众账号ID packageReqHandler.SetParameter("mch_id", TenPayV3Info.MchId); //商户号 packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 packageReqHandler.SetParameter("body", product.Name + " " + product.Code); //商品信息 packageReqHandler.SetParameter("out_trade_no", sp_billno); //商家订单号 decimal price = product.Price; packageReqHandler.SetParameter("total_fee", price.ToString()); //////////////////////商品金额,以分为单位(money * 100).ToString() packageReqHandler.SetParameter("spbill_create_ip", Request.UserHostAddress); //用户的公网ip,不是商户服务器IP packageReqHandler.SetParameter("notify_url", TenPayV3Info.TenPayV3Notify); //接收财付通通知的URL packageReqHandler.SetParameter("trade_type", TenPayV3Type.JSAPI.ToString()); //交易类型 packageReqHandler.SetParameter("openid", openIdResult.openid); //用户的openId string sign = packageReqHandler.CreateMd5Sign("key", TenPayV3Info.Key); packageReqHandler.SetParameter("sign", sign); //签名 string data = packageReqHandler.ParseXML(); var result = TenPayV3.Unifiedorder(data); var res = XDocument.Parse(result); string prepayId = res.Element("xml").Element("prepay_id").Value; //设置支付参数 RequestHandler paySignReqHandler = new RequestHandler(null); paySignReqHandler.SetParameter("appId", TenPayV3Info.AppId); paySignReqHandler.SetParameter("timeStamp", timeStamp); paySignReqHandler.SetParameter("nonceStr", nonceStr); paySignReqHandler.SetParameter("package", string.Format("prepay_id={0}", prepayId)); paySignReqHandler.SetParameter("signType", "MD5"); paySign = paySignReqHandler.CreateMd5Sign("key", TenPayV3Info.Key); ViewData["appId"] = TenPayV3Info.AppId; ViewData["timeStamp"] = timeStamp; ViewData["nonceStr"] = nonceStr; ViewData["package"] = string.Format("prepay_id={0}", prepayId); ViewData["paySign"] = paySign; return(View()); }