protected void Page_Load(object sender, EventArgs e) { Sys_FunctionRepository repository = new Sys_FunctionRepository(); if (Attributes["param"] != null) { string URL = Attributes["param"]; id = Util.GetParam(URL, "id"); if (string.IsNullOrEmpty(id)) { id = "0"; } if (id != "0") { Sys_Function entity = repository.GetById(int.Parse(id)); txtName.Text = entity.TenChucNang; txtMa.Text = entity.Ma; txtIcon.Text = entity.Icon; txtHref.Text = entity.Href; txtOrder.Text = entity.ThuTu != null?entity.ThuTu.ToString() : "0"; try { txtParent.Text = new xRPDataContext().Sys_Functions.FirstOrDefault(x => x.ID == entity.ParentID).TenChucNang; } catch { txtParent.Text = ""; } hdfParentID.Value = entity.ParentID != null?entity.ParentID.Value.ToString() : "0"; } } }
public static string AddOrUpdateFunctionItem(string id, string ma, string name, string parentID, string href, string icon, string thutu) { AjaxResponse response = new AjaxResponse(); xRPDataContext dts = new xRPDataContext(); var user = (from u in dts.aspnet_Users where u.UserName == HttpContext.Current.User.Identity.Name select u).FirstOrDefault(); try { string message = string.Empty; int groupdID = 0; string role = string.Empty; bool isExistName = false;// Sys_FunctionRepository repository = new Sys_FunctionRepository(); //response.IsSuccess = true; //response.Message = "Cập nhật thành công"; Sys_Function entity = new Sys_Function(); if (id != "") { entity = repository.GetById(int.Parse(id)); } else { entity.NgayTao = DateTime.Now; entity.MaNguoiTao = user.UserId; } entity.NgayThayDoi = DateTime.Now; entity.MaNguoiThayDoi = user.UserId; entity.Ma = ma; entity.TenChucNang = name; entity.ParentID = int.Parse(parentID); entity.Href = href; entity.Icon = icon; entity.Position = 1; entity.PhanHeID = 1; entity.ThuTu = int.Parse(thutu); if (id == "0") { repository.InsertOnSubmit(entity); } repository.SubmitChanges(); 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)); }