public static string AddOrUpdatePositionItem(string id, string name, bool isactive, string note) { AjaxResponse response = new AjaxResponse(); try { string message = string.Empty; int groupdID = 0; string role = string.Empty; bool isExistName = false;// Sys_DanhMucChucVuRepository repository = new Sys_DanhMucChucVuRepository(); //response.IsSuccess = true; //response.Message = "Cập nhật thành công"; Sys_DanhMucChucVu entity = new Sys_DanhMucChucVu(); if (id != "0") { entity = repository.GetById(int.Parse(id)); if (entity.TenChucVu != name) { isExistName = repository.IsExistName(name); } } else { isExistName = repository.IsExistName(name); } if (isExistName) { response.IsSuccess = false; response.Message = "Tên chức vụ đã tồn tại, vui lòng chọn tên khác"; return(JsonConvert.SerializeObject(response)); } entity.NgayThayDoi = DateTime.Now; entity.NgaySua = DateTime.Now; entity.NgayTao = DateTime.Now; entity.TenChucVu = name; entity.GhiChu = note; entity.KichHoat = isactive; if (id == "0") { repository.Add(entity); } repository.SubmitChanges(); groupdID = entity.ID; response.IsSuccess = true; response.Message = "Cập nhật thành công"; } catch (Exception ex) { response.IsSuccess = false; response.Message = (ex.Message + ex.StackTrace).EncodeJsString(); } return(JsonConvert.SerializeObject(response)); }
protected void btnSave_Click(object sender, EventArgs e) { try { int groupdID = 0; string name = txtName.Text; string role = string.Empty; bool isExistName = false;// Sys_DanhMucChucVu entity = new Sys_DanhMucChucVu(); if (id != "0") { entity = repository.GetById(int.Parse(id)); if (entity.TenChucVu != txtName.Text) { isExistName = repository.IsExistName(name); } } else { isExistName = repository.IsExistName(name); } if (isExistName) { //lblNameError.Text = "Tên chức vụ đã tồn tại, vui lòng chọn tên khác"; //lblNameError.Visible = true; ClientScriptManager cs = Page.ClientScript; String cstext1 = "alert('Tên chức vụ đã tồn tại, vui lòng chọn tên khác');"; cs.RegisterStartupScript(this.GetType(), "alert", cstext1, true); return; } entity.NgayThayDoi = DateTime.Now; entity.NgaySua = DateTime.Now; entity.NgayTao = DateTime.Now; entity.TenChucVu = txtName.Text; entity.GhiChu = txtNote.Text; entity.KichHoat = ckKichHoat.Checked; if (id == "0") { repository.Add(entity); } repository.SubmitChanges(); groupdID = entity.ID; Response.Redirect("default.aspx?page=position"); } catch (Exception ex) { //lblMessage.CssClass = "error"; //lblMessage.Visible = true; //lblMessage.Text = "Lỗi trong quá trình cập nhật, lỗi: " + ex.Message; string message = "Lỗi trong quá trình cập nhật, lỗi: " + ex.Message; String cstext2 = "alert('" + message + "');"; Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", cstext2, true); } }