public IHttpActionResult PostCategory(CategoryDTO category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Category c = CategoryConverter.DTOToDAL(category); CategoryBLL.Add(c); try { Global.SaveChanges(); } catch (DbUpdateException) { if (CategoryExists(category.code)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = category.code }, category)); }
protected void btnSave_Click(object sender, EventArgs e) { if (txtCategoryName.Text == "") { txtCategoryName.Focus(); return; } CDTO.CategoryName = txtCategoryName.Text.ToString(); CDTO.CreateDate = System.DateTime.Now; CDTO.CreateBy = "tarun"; if (btnSave.Text == "Save") { CBLL.Add(CDTO); pagingLoal(); clearCntrol(); } else { CDTO.CatId = Convert.ToInt32(HFUID.Value); CDTO.UpdateDate = System.DateTime.Now; CDTO.UpdateBy = "tarun"; CBLL.Edit(CDTO); btnSave.Text = "Save"; pagingLoal(); clearCntrol(); } }
public ActionResult AddCate(string CateName, int Sort, int ParentId = 0) { MsgBase msg = new MsgBase(); try { Category cate = cateBll.GetByName(CateName.Trim()); if (cate == null) { Category model = new Category() { CateName = CateName.Trim(), ParentId = ParentId, Sort = Sort }; int i = cateBll.Add(model); msg.Message = i > 0 ? MsgBase.SuccessMessage : MsgBase.FailMessage; msg.Code = i > 0 ? 1 : 0; } else { msg.Code = 2; msg.Message = "分类已经存在"; } } catch (Exception) { msg.Code = -1; msg.Message = MsgBase.ErrMessage; } return(Json(msg)); }
protected void btnSave_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["catId"]); CategoryBLL cb = new CategoryBLL(); if (Request.QueryString["catId"] == null) { Category c = new Category(); c.Name = txtName.Text; c.IsActive = true; c.Date = DateTime.Now; cb.Add(c); } else { Category c = cb.Get(x => x.Id == id).FirstOrDefault(); c.Name = txtName.Text; c.IsActive = true; c.Date = DateTime.Now; cb.Update(c); } Response.Redirect("Categories.aspx"); }
protected void CategoryDisplayGrid_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName.Equals("Add")) { CategoryBLL categoryManager = new CategoryBLL(); TextBox txtname = (TextBox)CategoryDisplayGrid.FooterRow.FindControl("txtAddname"); // TextBox txtDepId = (TextBox)CategoryDisplayGrid.FooterRow.FindControl("txtAddDepID"); string depName = (CategoryDisplayGrid.FooterRow.FindControl("ddlAddDepName") as DropDownList).SelectedItem.Value; Category categoryToAdd = new Category(); categoryToAdd.Name = txtname.Text; int res; if (int.TryParse(depName, out res)) { categoryToAdd.DepartmentID = res; categoryManager.Add(categoryToAdd); } else { WebMessageBoxUtil.Show("Invalid input in Department field "); } } else if (e.CommandName.Equals("UpdateCategory")) { CategoryBLL categoryManager = new CategoryBLL(); Label id = (Label)CategoryDisplayGrid.Rows[CategoryDisplayGrid.EditIndex].FindControl("lblCat_ID"); TextBox name = (TextBox)CategoryDisplayGrid.Rows[CategoryDisplayGrid.EditIndex].FindControl("txtname"); DropDownList ddlDep = (DropDownList)(CategoryDisplayGrid.Rows[CategoryDisplayGrid.EditIndex].FindControl("ddlDepName")); string depName = ddlDep.SelectedItem.Value; // TextBox departmentId = (TextBox)CategoryDisplayGrid.Rows[e.RowIndex].FindControl("txtDepID"); int selectedId = int.Parse(id.Text); Category categoryToUpdate = new Category();//= empid.Text; categoryToUpdate.CategoryID = selectedId; categoryToUpdate.Name = name.Text; int res; if (int.TryParse(depName, out res)) { categoryToUpdate.DepartmentID = int.Parse(depName); categoryManager.Update(categoryToUpdate); } else { WebMessageBoxUtil.Show("Invalid input in Department field "); } } } catch (Exception exp) { } finally { CategoryDisplayGrid.EditIndex = -1; BindGrid(false); } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (txtCategoryName.Text == "") { txtCategoryName.Focus(); return; } CDTO.CategoryName = txtCategoryName.Text.ToString(); CDTO.CreateDate = System.DateTime.Now; CDTO.CreateBy = HttpContext.Current.User.Identity.Name; if (btnSave.Text == "Save") { CBLL.Add(CDTO); pagingLoal(); clearCntrol(); } else { CDTO.CatId = Convert.ToInt32(HFUID.Value); CDTO.UpdateDate = System.DateTime.Now; CDTO.UpdateBy = HttpContext.Current.User.Identity.Name; CBLL.Edit(CDTO); btnSave.Text = "Save"; pagingLoal(); clearCntrol(); } } catch (Exception ex) { Show(ex.Message); } }
protected void btnSave_Click(object sender, EventArgs e) { model.CategoryName = KillSqlIn.Form_ReplaceByString(Request.Form["txtTitle"], 200); model.Sort = Convert.ToInt32(KillSqlIn.Form_ReplaceByNumber(Request.Form["txtSort"], 4)); model.AddedUserId = Convert.ToInt32(_userId); model.AddedDate = Convert.ToDateTime(this.txtAddDate.Text); model.ParentCategoryId = Convert.ToInt32(this.ddlParentCategory.SelectedValue); model.Type = 0;//0:文章 1:新闻 //string BackUrl = "CategoryTree.aspx"; if (_ACid != "0") { model.CategoryId = Convert.ToInt32(_ACid); bll.Update(model); ClientScript.RegisterStartupScript(this.GetType(), "js", "<script>alert('修改成功!');layer_close_refresh();</script>"); //JSUtility.AlertAndRedirect("修改成功!", BackUrl); /*日志归档*/ //string sql1 = @"select Title as title from dbo.T_Category where CategoryId = (" + _ACid + ")"; //string function = "修改"; //PubFunction.InsertLog1("文章类别管理", sql1, function); } else { model.AddedDate = DateTime.Now; int id = bll.Add(model); bll.UpdateCategoryPermission(id.ToString()); JSUtility.AlertAndRedirect("添加成功,请继续添加!", Request.RawUrl.ToString()); /*日志归档*/ //string sql1 = @"select Title as title from dbo.T_Category where CategoryId = (select top 1 CategoryId from T_Category order by CategoryId desc)"; //string function = "添加"; //PubFunction.InsertLog1("文章类别管理", sql1, function); } }
public string Add(CategoryDTO category) { return(categoryBLL.Add(category)); }
//新增、更新和删除时,存盘的工作 private void btnSave_Click(object sender, EventArgs e) { switch (op) { case EnumOperation.Insert: _categoryObj = new Category() { CategoryName = txtCategoryName.Text.Trim() }; //检测是否有重复的分类 if (_list.FirstOrDefault(x => x.CategoryName == _categoryObj.CategoryName) != null) { MessageBox.Show("不能添加重复的分类"); return; } if (_categoryBll.Add(_categoryObj)) { //重新查询数据,并对正处理的数据记录进行定位 QueryData(); var id = _list.FirstOrDefault(x => x.CategoryName == _categoryObj.CategoryName).CategoryID; LocationNewRow(id); } break; case EnumOperation.Update: if (_categoryObj != null) { _categoryObj.CategoryName = txtCategoryName.Text.Trim(); if (_categoryBll.Edit(_categoryObj)) { //重新查询数据,并对正处理的数据记录进行定位 QueryData(); var id = _list.FirstOrDefault(x => x.CategoryName == _categoryObj.CategoryName).CategoryID; LocationNewRow(id); } } else { MessageBox.Show("请先选择一条分类记录"); return; } break; case EnumOperation.Delete: if (_categoryObj != null) { if (_categoryBll.Delete(_categoryObj)) { MessageBox.Show("删除成功"); QueryData(); } } else { MessageBox.Show("请先选择一条分类记录"); return; } break; case EnumOperation.None: default: break; } }
protected void ibtnAdd_Click(object sender, EventArgs e) { //验证代码 try { if (string.IsNullOrEmpty(Request.QueryString["type"] + "")) { Category model = new Category(); model.codeNo = txtCode.Text.Trim().Replace(" ", ""); model.id = int.Parse(hdfnodeID.Value); model.parentID = int.Parse(hdfparentID.Value); model.title = txtTitle.Text; model.orderId = int.Parse(hdforderID.Value); model.description = hdfDes.Value; model.stateID = ddlState.SelectedIndex; model.imgPath = hdfImg.Value; model.typeID = int.Parse(rbtType.SelectedItem.Value + ""); model.outLink = txtLink.Text; bll.Update(model); Response.Redirect("Default.aspx?id=" + model.id, false); } else { if (!string.IsNullOrEmpty(Request.QueryString["type"] + "")) { Category model = new Category(); model.title = txtTitle.Text; model.codeNo = txtCode.Text; // 防止网页重复提交 if (!bll.ExistsCode(model.codeNo)) { try { model.parentID = int.Parse(Request.QueryString["pid"]); } catch { Msg.Show("参数错误!"); } model.orderId = bll.GetChildNum(model.parentID); model.description = ""; model.stateID = ddlState.SelectedIndex; model.typeID = rbtType.SelectedIndex; model.outLink = txtLink.Text; // model.imgPath = int res = bll.Add(model); Response.Redirect("Default.aspx?id=" + res, false); } else { Msg.Show("编码已存在!"); } } } } catch (Exception ex) { log.Error(ex.Message); Msg.Show("网络错误!原因:" + ex.Message); } }