protected void btnSave_Click(object sender, EventArgs e) { try { // Validate input value if (string.IsNullOrEmpty(txtUserName.Value.Trim()) || string.IsNullOrEmpty(txtEmail.Value.Trim()) ) { txtMess.ForeColor = Color.Red; txtMess.Text = "Missing input data!"; return; } // Account logged = (Account)Session["LoggedAccount"]; int Id = Int32.Parse(AccountID.Value); LPS.Account obj = db.Accounts.FirstOrDefault(x => x.AccountId == Id); if (obj != null) { if (radioAdmin.Checked) { obj.AccountType = Common.TypeAdmin; } else { obj.AccountType = Common.TypeUser; } obj.Active = true; //obj.CreateBy = logged.UserName ; obj.Email = txtEmail.Value.Trim(); obj.FullName = txtFullName.Value.Trim(); obj.ModifyDate = DateTime.Now; if (!string.IsNullOrEmpty(txtPassword.Value.Trim())) { if (txtPassword.Value.Trim().ToLower() == txtPasswordConfirm.Value.Trim().ToLower()) { obj.Password = haenClass.SHA256Hash(txtPassword.Value.Trim()); } else { txtMess.ForeColor = Color.Red; txtMess.Text = "Password confirm not match!"; return; } } db.SaveChanges(); LoadData(); txtMess.ForeColor = Color.Green; txtMess.Text = "The account with username " + obj.UserName + " was updated successful"; } } catch (Exception ex) { txtMess.ForeColor = Color.Red; txtMess.Text = ex.Message; } }
private void LoadData() { if (!comClass.IsNumeric(Request.QueryString.Get("Id"))) { Response.Redirect(BackUrl.Value); } else { int Id = Int32.Parse(Request.QueryString.Get("Id")); LPS.Account obj = new LPS.Account(); obj = db.Accounts.FirstOrDefault(x => x.AccountId == Id); AccountID.Value = obj.AccountId.ToString(); txtEmail.Value = obj.Email; txtFullName.Value = obj.FullName; txtUserName.Value = obj.UserName; txtUserName.Disabled = true; txtPassword.Value = string.Empty; txtPasswordConfirm.Value = string.Empty; if (obj.AccountType.Trim() == Common.TypeAdmin) { radioAdmin.Checked = true; } else { radioUser.Checked = true; } //chkPCActive.Checked = obj.Active; } }
protected void btnSave_Click(object sender, EventArgs e) { try { // Validate input value if (string.IsNullOrEmpty(txtUserName.Value.Trim()) || string.IsNullOrEmpty(txtPassword.Value.Trim()) || txtPassword.Value != txtPasswordConfirm.Value || string.IsNullOrEmpty(txtEmail.Value.Trim()) ) { txtMess.ForeColor = Color.Red; txtMess.Text = "Missing input data!"; return; } // Check username if exist if (db.Accounts.FirstOrDefault(x => x.UserName == txtUserName.Value.Trim()) != null) { txtMess.ForeColor = Color.Red; txtMess.Text = "This Username was existed"; return; } LPS.Account obj = new LPS.Account(); if (radioAdmin.Checked) { obj.AccountType = Common.TypeAdmin; } else { obj.AccountType = Common.TypeUser; } obj.Active = true; obj.CreateBy = logged.UserName; obj.CreateDate = DateTime.Now; obj.Email = txtEmail.Value.Trim(); obj.FullName = txtFullName.Value.Trim(); obj.ModifyDate = DateTime.Now; obj.Password = haenClass.SHA256Hash(txtPassword.Value.Trim()); obj.UserName = txtUserName.Value.Trim(); db.Accounts.Add(obj); db.SaveChanges(); LoadData(); txtMess.ForeColor = Color.Green; txtMess.Text = "The account with username " + obj.UserName + " was created successful"; } catch (Exception ex) { txtMess.ForeColor = Color.Red; txtMess.Text = ex.Message; return; } }
protected void btnSave_Click(object sender, EventArgs e) { try { // Validate input value if (string.IsNullOrEmpty(txtUserName.Value.Trim()) || string.IsNullOrEmpty(txtPassword.Value.Trim()) || txtPassword.Value != txtPasswordConfirm.Value || string.IsNullOrEmpty(txtEmail.Value.Trim()) ) { txtMess.ForeColor = Color.Red; txtMess.Text = "Missing input data!"; return; } // Check username if exist if (db.Accounts.FirstOrDefault(x => x.UserName == txtUserName.Value.Trim()) != null) { txtMess.ForeColor = Color.Red; txtMess.Text = "This Username was existed"; return; } LPS.Account obj = new LPS.Account(); if(radioAdmin.Checked) obj.AccountType = Common.TypeAdmin; else obj.AccountType = Common.TypeUser; obj.Active = true; obj.CreateBy = logged.UserName; obj.CreateDate = DateTime.Now; obj.Email = txtEmail.Value.Trim(); obj.FullName = txtFullName.Value.Trim(); obj.ModifyDate = DateTime.Now; obj.Password = haenClass.SHA256Hash(txtPassword.Value.Trim()); obj.UserName = txtUserName.Value.Trim(); db.Accounts.Add(obj); db.SaveChanges(); LoadData(); txtMess.ForeColor = Color.Green; txtMess.Text = "The account with username "+obj.UserName+" was created successful"; } catch (Exception ex) { txtMess.ForeColor = Color.Red; txtMess.Text = ex.Message; return; } }
protected void gvListItem_RowCommand(object sender, GridViewCommandEventArgs e) { int id = Int32.Parse(e.CommandArgument.ToString()); GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer); if (e.CommandName.ToLower() == "deleteitem") { // Don't allow deleted it seft if (logged.AccountId == id) { txtMess.ForeColor = Color.Red; txtMess.Text = "You can't delete your self"; return; } LPS.Account obj = db.Accounts.Find(id); db.Accounts.Remove(obj); db.SaveChanges(); LoadData(); txtMess.ForeColor = Color.Green; txtMess.Text = "User account has been deleted"; } }
private void LoadData() { if (!comClass.IsNumeric(Request.QueryString.Get("Id"))) { Response.Redirect(BackUrl.Value); } else { int Id = Int32.Parse(Request.QueryString.Get("Id")); LPS.Account obj = new LPS.Account(); obj = db.Accounts.FirstOrDefault(x => x.AccountId == Id); AccountID.Value = obj.AccountId.ToString(); txtEmail.Value = obj.Email; txtFullName.Value = obj.FullName; txtUserName.Value = obj.UserName; txtUserName.Disabled = true; txtPassword.Value = string.Empty; txtPasswordConfirm.Value = string.Empty; if (obj.AccountType.Trim()== Common.TypeAdmin) radioAdmin.Checked = true; else radioUser.Checked = true; //chkPCActive.Checked = obj.Active; } }