protected void cmdCreate_Click(object sender, EventArgs e) { using (PTCLEntities db = new PTCLEntities()) { if (Request.QueryString["AdminID"] == null) { tblAdmin s = new tblAdmin(); s.UserName = txtUserName.Text; //s.Password = txtPassword.Text; s.FullName = txtFullName.Text; s.EmailAddress = txtEmailAddress.Text; s.Location = txtLocation.Text; s.AdminPhone = txtPhone.Text; if (FileUpload.HasFile) { FileUpload.SaveAs(Server.MapPath("../../UploadFiles/AdminProfile/" + FileUpload.FileName)); s.AdminDP = FileUpload.FileName; } else { s.AdminDP = ""; } var password = txtPassword.Text; var salt = CreateSalt(); var hash = HashPassword(password, salt); s.Password = Convert.ToBase64String(hash); //s.Status = txtStatus.Text; s.Status = bool.Parse(ddlStatus.SelectedValue.ToString()); // s.Status = Boolean.TryParse(ddlStatus.SelectedValue.ToString); var check = db.uniqueEmail(txtEmailAddress.Text).ToList(); var check1 = db.uniqueUserName(txtUserName.Text).ToList(); if (check.Count == 0) { if (check1.Count == 0) { db.tblAdmins.Add(s); db.SaveChanges(); lblMsg.Text = "Admin Inserted Successfully"; } else { lblMsg.Text = "UserName Already Takken"; } } else { lblMsg.Text = "Email Already Takken"; } } else { var password = txtPassword.Text; var salt = CreateSalt(); var hash = HashPassword(password, salt); int AdminID = Convert.ToInt32(Request.QueryString["AdminID"]); tblAdmin s = db.tblAdmins.FirstOrDefault(v => v.AdminID == AdminID); s.Password = Convert.ToBase64String(hash); s.UserName = txtUserName.Text; //s.Password = txtPassword.Text; s.FullName = txtFullName.Text; s.EmailAddress = txtEmailAddress.Text; s.Location = txtLocation.Text; s.AdminPhone = txtPhone.Text; if (FileUpload.HasFile) { FileUpload.SaveAs(Server.MapPath("../../UploadFiles/AdminProfile/" + FileUpload.FileName)); s.AdminDP = FileUpload.FileName; } else { s.AdminDP = ""; } //s.Status = txtStatus.Text; s.Status = bool.Parse(ddlStatus.SelectedValue); //s.Status = bool.Parse(ddlStatus.SelectedValue.ToString()); //s.Status = Convert.ToBoolean(ddlStatus.SelectedValue); var check = db.uniqueEmail(txtEmailAddress.Text).ToList(); var check1 = db.uniqueUserName(txtUserName.Text).ToList(); if (check.Count == 1) { if (check1.Count == 1) { db.SaveChanges(); lblMsg.Text = "Admin Updated Successfully"; } else { lblMsg.Text = "UserName Already Takken"; } } else { lblMsg.Text = "Email Already Takken"; } } } }