/// <summary> /// 添加或编辑广告位信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public static AdPositionInfo Create(AdPositionInfo model){ if(model.Id == 0){ int id=AdPositionManage.Insert(model); }else{ AdPositionManage.Update(model); } return model; }
public ActionResult Create(AdPositionInfo model) { bool errors = false; if (string.IsNullOrEmpty(model.Name)) { ModelState.AddModelError("NAME", "广告名称不能为空"); errors = true; } if(ModelState.IsValid && !errors){ AdPositionService.Create(model); ViewBag.Msg = "添加成功!<a href=\"/adm/slot/list\">返回</a>"; } return View(); }
/// <summary> /// 添加新的广告位 /// </summary> /// <param name="model"></param> /// <returns></returns> public static int Insert(AdPositionInfo model) { string strSQL = "INSERT INTO dbo.AdPosition(Name,Width,Height,Remark) VALUES(@Name,@Width,@Height,@Remark);SELECT @@IDENTITY;"; SqlParameter[] parms = { new SqlParameter("Name",SqlDbType.NVarChar), new SqlParameter("Width",SqlDbType.Int), new SqlParameter("Height",SqlDbType.Int), new SqlParameter("Remark",SqlDbType.NVarChar) }; parms[0].Value = model.Name; parms[1].Value = model.Width; parms[2].Value = model.Height; parms[3].Value = model.Remark; return Convert.ToInt32(SQLPlus.ExecuteScalar(CommandType.Text,strSQL,parms)); }
/// <summary> /// 更新广告位 /// </summary> /// <param name="model"></param> /// <returns></returns> public static int Update(AdPositionInfo model) { string strSQL = "UPDATE AdPosition SET Name = @Name,Width = @Width,Height = @Height,Remark = @Remark,DeliveryUrl = @DeliveryUrl WHERE Id = @Id"; SqlParameter[] parms = { new SqlParameter("Name",SqlDbType.NVarChar), new SqlParameter("Width",SqlDbType.Int), new SqlParameter("Height",SqlDbType.Int), new SqlParameter("Remark",SqlDbType.NVarChar), new SqlParameter("Id",SqlDbType.Int), new SqlParameter("DeliveryUrl",SqlDbType.NVarChar), }; parms[0].Value = model.Name; parms[1].Value = model.Width; parms[2].Value = model.Height; parms[3].Value = model.Remark; parms[4].Value = model.Id; parms[5].Value = "sss"; return SQLPlus.ExecuteNonQuery(CommandType.Text, strSQL, parms); }