//更新商品信息 public ActionResult UpdateGoodsCallBack(AddGoodsCallBackIn InModel) { string errorType = ""; string msg = "OK"; Model.GoodsBaseInfo goodsInfo = new Model.GoodsBaseInfo() { ID = InModel.ID, GoodsName = InModel.GoodsName, Price = InModel.Price, Describe = InModel.Describe, Category = InModel.Category, ShowIcons = string.IsNullOrEmpty(InModel.ShowIcons) ? "" : InModel.ShowIcons.Remove(InModel.ShowIcons.Length - 1), DetailIcons = string.IsNullOrEmpty(InModel.DetailIcons) ? "" : InModel.DetailIcons.Remove(InModel.DetailIcons.Length - 1), CreateUserID = Identity.LoginUserInfo.UserID.ToString(), CreateTime = DateTime.Now.ToString() }; bool result = BLL.GoodsBaseInfoBll.UpDateGoodsInfo(goodsInfo); if (!result) { errorType = "alert"; msg = "添加失败,请重试"; } return(Json(new { Message = msg, ErrorType = errorType }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 增加后返回ID提供给下一个页面进行更新 /// </summary> /// <param name="entity"></param> /// <returns></returns> public static string AddGoodsInfo(Model.GoodsBaseInfo entity) { var sql = @" INSERT INTO [GoodsBaseInfo] ( GoodsName ,Price ,Describe ,Category ,CreateUserID ,CreateTime ,IsDelete ,IsHot ) VALUES ( @GoodsName ,@Price ,@Describe ,@Category ,@CreateUserID ,@CreateTime ,0 ,0 );SELECT SCOPE_IDENTITY()"; var parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter() { ParameterName = "@GoodsName", Value = entity.GoodsName }); parameters.Add(new SqlParameter() { ParameterName = "@Price", Value = entity.Price }); parameters.Add(new SqlParameter() { ParameterName = "@Describe", Value = entity.Describe }); parameters.Add(new SqlParameter() { ParameterName = "@Category", Value = entity.Category }); parameters.Add(new SqlParameter() { ParameterName = "@CreateUserID", Value = entity.CreateUserID }); parameters.Add(new SqlParameter() { ParameterName = "@CreateTime", Value = entity.CreateTime }); try { return(SqlHelper.ExecuteScalar(sql, parameters.ToArray()).ToString()); } catch { return(""); } }
//添加商品信息 public ActionResult AddGoodsCallBack(AddGoodsCallBackIn InModel) { string errorType = ""; string msg = "OK"; //用来返回刚插入的记录的ID string insertID = ""; // 验证参数 if (string.IsNullOrWhiteSpace(InModel.GoodsName)) { errorType = "GoodsName"; msg = "请输入商品名称"; } else if (BLL.BackgroundUserBll.IsExistUserName(InModel.Describe)) { errorType = "Describe"; msg = "请输入商品详情"; } else if (string.IsNullOrWhiteSpace(InModel.Price)) { errorType = "Price"; msg = "请输入商品价格"; } else if (string.IsNullOrWhiteSpace(InModel.Category)) { errorType = "Category"; msg = "请选择商品类别"; } else { // 添加用户 Model.GoodsBaseInfo goodsInfo = new Model.GoodsBaseInfo() { GoodsName = InModel.GoodsName, Price = InModel.Price, Describe = InModel.Describe, Category = InModel.Category, CreateUserID = Identity.LoginUserInfo.UserID.ToString(), CreateTime = DateTime.Now.ToString() }; insertID = BLL.GoodsBaseInfoBll.AddGoodsInfo(goodsInfo); if (string.IsNullOrEmpty(insertID)) { errorType = "alert"; msg = "添加失败,请重试"; } } return(Json(new { Message = msg, ErrorType = errorType, InsertID = insertID }, JsonRequestBehavior.AllowGet)); }
public static bool UpDateGoodsInfo(Model.GoodsBaseInfo entity) { var sql = @"UPDATE [GoodsBaseInfo] SET {0} WHERE ID=@ID"; var parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter() { ParameterName = "@ID", Value = entity.ID }); string sqlPart = string.Empty; if (!string.IsNullOrEmpty(entity.GoodsName)) { parameters.Add(new SqlParameter() { ParameterName = "@GoodsName", Value = entity.GoodsName }); sqlPart += "GoodsName=@GoodsName,"; } if (!string.IsNullOrEmpty(entity.Price)) { parameters.Add(new SqlParameter() { ParameterName = "@Price", Value = entity.Price }); sqlPart += "Price=@Price,"; } if (!string.IsNullOrEmpty(entity.Describe)) { parameters.Add(new SqlParameter() { ParameterName = "@Describe", Value = entity.Describe }); sqlPart += "Describe=@Describe,"; } if (!string.IsNullOrEmpty(entity.Category)) { parameters.Add(new SqlParameter() { ParameterName = "@Category", Value = entity.Category }); sqlPart += "Category=@Category,"; } if (!string.IsNullOrEmpty(entity.ShowIcons)) { parameters.Add(new SqlParameter() { ParameterName = "@ShowIcons", Value = entity.ShowIcons }); sqlPart += "ShowIcons=@ShowIcons,"; } if (!string.IsNullOrEmpty(entity.DetailIcons)) { parameters.Add(new SqlParameter() { ParameterName = "@DetailIcons", Value = entity.DetailIcons }); sqlPart += "DetailIcons=@DetailIcons,"; } if (string.IsNullOrEmpty(sqlPart)) { //没变化默认为更新成功 return(true); } else { sqlPart = sqlPart.Remove(sqlPart.Length - 1); } sql = string.Format(sql, sqlPart); try { return(SqlHelper.ExecuteNonQuery(sql, parameters.ToArray()) > 0 ? true : false); } catch { return(false); } }
//查看商品页面 public ActionResult GetGoodsInfo(string goodsID) { Model.GoodsBaseInfo outModel = BLL.GoodsBaseInfoBll.GetGoodsInfoByID(goodsID); return(View(outModel)); }
public static string AddGoodsInfo(Model.GoodsBaseInfo InModel) { return(DAL.GoodsBaseInfoDal.AddGoodsInfo(InModel)); }
public static bool UpDateGoodsInfo(Model.GoodsBaseInfo InModel) { return(DAL.GoodsBaseInfoDal.UpDateGoodsInfo(InModel)); }