private void addButton_Click(object sender, EventArgs e) { AddAdmin aAddAdmin = new AddAdmin(); aAddAdmin.UserName = nameTextBox.Text; aAddAdmin.Password = passwordTextBox.Text; aAddAdmin.Role = rollTextBox.Text; AddAdminBL AddAdminBLOBj = new AddAdminBL(); bool result = AddAdminBLOBj.AddAdminToDB(aAddAdmin); if (result) { MessageBox.Show("Successfully Added new User!", "DONE"); nameTextBox.Clear(); passwordTextBox.Clear(); rollTextBox.Clear(); } else { DialogResult dialog = MessageBox.Show("Please fill all the text", "ERROR", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (dialog == DialogResult.Cancel) { this.Close(); } } }
private void createAdminToolStripMenuItem1_Click(object sender, EventArgs e) { panel1.Controls.Clear(); AddAdmin add = new AddAdmin(); panel1.Controls.Add(add); }
/// <summary> /// Constructor with edit admin window opening /// </summary> /// <param name="addAdminOpen">opens the edit admin window</param> /// <param name="adminEdit">gets the admin info that is being edited</param> public AddUserViewModel(AddAdmin addAdminOpen, vwAdmin adminEdit) { admin = adminEdit; addAdmin = addAdminOpen; AllInfoAdminList = service.GetAllAdminsInfo().ToList(); AdminList = service.GetAllAdmins().ToList(); UserList = service.GetAllUsers().ToList(); }
public async Task <ActionResult> RegisterAdmin(AdminRegistration model) { string email = User.Identity.Name; string type = null; string Type1 = null; UETCSEDbEntities dbo = new UETCSEDbEntities(); foreach (AddAdmin reg in dbo.AddAdmins) { if (reg.Email == email) { type = reg.Type; Type1 = reg.Type1; break; } } if (type == null && Type1 == null) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user /*, model.Password*/); if (result.Succeeded) { //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); UETCSEDbEntities db = new UETCSEDbEntities(); var AdminName = model.AdminName; var Email = model.Email; var Type = "Admin"; AddAdmin ad = new AddAdmin(); ad.Email = Email; ad.Name = AdminName; ad.Type = Type; db.AddAdmins.Add(ad); db.SaveChanges(); SendMailToUser(model.Email); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToLocal("~/Admin/SuperAdmin")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
private void AddAdminExecute() { try { AddAdmin addAdmin = new AddAdmin(); addAdmin.Show(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public bool AddAdminToDB(AddAdmin aAddAdmin) { if (aAddAdmin.UserName == "" || aAddAdmin.Password == "" || aAddAdmin.Role == "") { return(false); } else { AddAdminDA addAdminDAOBj = new AddAdminDA(); bool result = addAdminDAOBj.SaveNewAdminToDB(aAddAdmin); return(result); } }
private void createAdminExecute() { try { AddAdmin addAdmin = new AddAdmin(); masterWindow.Close(); addAdmin.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new AddAdmin { UserName = Input.Email, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName, Designation = Input.Designation, Address = Input.Address, PhoneNumber = Input.PhoneNumber }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); var addToRoleResult = await _userManager.AddToRoleAsync(user, "Admin"); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl })); } else { await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public AddAdminViewModel(AddAdmin addAdminView) { view = addAdminView; AdministratorTypesList = new List <string>() { "Team", "System", "Local" }; adminService = new AdminService(); userService = new UserService(); managerService = new ManagerService(); User = new tblUser(); Admin = new tblAdmin(); }
public bool SaveNewAdminToDB(AddAdmin aAddAdmin) { SqlConnection connection = DataBaseConnection.OpenAnSqlConnection(); string query = "INSERT INTO AdminTAble VALUES ('" + aAddAdmin.UserName + "', '" + aAddAdmin.Password + "','" + aAddAdmin.Role + "')"; SqlCommand command = new SqlCommand(query, connection); int rowsAffected = command.ExecuteNonQuery(); if (rowsAffected == 1) { return(true); } else { return(false); } }
public async Task <ActionResult> Login(string Name, string password) { Adminsignup A = new Adminsignup(); AddAdmin admin = new AddAdmin(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:52995/"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Accept.Clear(); //HttpResponseMessage response, response1; //if (Name ==A.first_name ||password == A.confirm_pswd) //{ // response = await client.PostAsJsonAsync("guestLogin", A); // if (response.IsSuccessStatusCode == true) // { // Response.Cookies.Clear(); // ModelState.Clear(); // // return View("_Layout.cshtml"); // return View(); // } //} //else //{ //} //if (Name == admin.full_name || password == admin.password) //{ // response1 = await client.PostAsJsonAsync("AdminLogin", A); // if (response1.IsSuccessStatusCode == true) // { // Response.Cookies.Clear(); // ModelState.Clear(); // // return View("_Layout.cshtml"); // return View(); // } //} HttpResponseMessage response = await client.PostAsJsonAsync("guestLogin", A); if (response.IsSuccessStatusCode == true) { Response.Cookies.Clear(); ModelState.Clear(); // return View("_Layout.cshtml"); return(View()); } return(View()); }
/// <summary> /// Executes the add Admin command /// </summary> private void AddNewAdminExecute() { try { AddAdmin addAdmin = new AddAdmin(); addAdmin.ShowDialog(); if ((addAdmin.DataContext as AddUserViewModel).IsUpdateAdmin == true) { AdminList = service.GetAllAdmins().ToList(); AllInfoAdminList = service.GetAllAdminsInfo().ToList(); UserList = service.GetAllUsers().ToList(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Adds admin to database /// </summary> /// <param name="addAdmin">New admin data</param> public void AddAdmin(AddAdmin addAdmin) { using (MySqlConnection connection = WebApiConfig.Connection()) using (MySqlCommand command = new MySqlCommand($"INSERT INTO `tbAdminAccounts`() VALUES (null, @Username, @Email, @Enable, @Password, null)", connection)) { connection.Open(); command.Parameters.AddWithValue("@Email", addAdmin.Email); command.Parameters.AddWithValue("@Username", addAdmin.Username); command.Parameters.AddWithValue("@Enable", addAdmin.Enabled); command.Parameters.AddWithValue("@Password", Verification.BcryptPasswordInBase64(addAdmin.Password)); command.ExecuteNonQuery(); int AdminId = NextAutoIncrement("tbAdminAccounts") - 1; foreach (var item in addAdmin.Permissions) { command.CommandText = $"INSERT INTO `tbPermissions`() VALUES (null,{item},{AdminId})"; command.ExecuteNonQuery(); } } }
public ActionResult EditAdmin(int uid) { var emailid = User.Identity.Name.ToString(); Users admin = dbobj.Users.Where(x => x.EmailID == emailid).FirstOrDefault(); Users adobj = dbobj.Users.Where(x => x.ID == uid).FirstOrDefault(); Admin admin_profile = dbobj.Admin.Where(x => x.UserID == uid).FirstOrDefault(); AddAdmin model = new AddAdmin(); model.UserID = adobj.ID; model.FirstName = adobj.FirstName; model.LastName = adobj.LastName; model.Email = adobj.EmailID; model.CountryCode = admin_profile.CountryCode; model.PhoneNumber = admin_profile.PhoneNumber; ViewBag.CountryCodelist = new SelectList(dbobj.Countries, "CountryCode", "CountryCode"); ViewBag.ProfilePicture = dbobj.Admin.Where(x => x.UserID == admin.ID).Select(x => x.ProfilePicture).FirstOrDefault(); return(View(model)); }
private void addButton_Click(object sender, EventArgs e) { AddAdmin aAddAdmin = new AddAdmin(); aAddAdmin.name = nameTextBox.Text; aAddAdmin.password = passwordTextBox.Text; aAddAdmin.role = rollTextBox.Text; AddAdminBL AddAdminBLOBj = new AddAdminBL(); bool result = AddAdminBLOBj.AddAdminToDB(aAddAdmin); if (result) { MessageBox.Show("Success!!!"); nameTextBox.Clear(); passwordTextBox.Clear(); rollTextBox.Clear(); } else { MessageBox.Show("ERROR!!!!"); } }
public AddAdminViewModel(AddAdmin addAdminOpen) { addAdmin = addAdminOpen; seerviceAdmin = new SeerviceAdmin(); Admin = new vwAdmin(); }
public async Task <IActionResult> AddingAdmin(AddAdmin userModel) { string role = User.Claims.ElementAt(1).Value; if (role != UserRole.SystemAdmin.ToString()) { return(BadRequest(new { message = "Bad data" })); } var applicationUser = new User() { UserName = userModel.AdminUsername, Email = userModel.Email, Name = "", Surname = "", PhoneNumber = "", Address = userModel.Address, }; //if (userModel.TypeOfCompany == "airline") //{ // Airline air = new Airline(); // air.Adress = userModel.Address; // air.Description = userModel.Description; // air.CompanyName = userModel.CompanyName; // applicationUser.Role = UserRole.AirlineAdmin; // try // { // var result = await _userManager.CreateAsync(applicationUser, userModel.Email); // var kk1 = await _userManager.FindByEmailAsync(userModel.Email); // kk1.AirlineComnpany = air; // _context.Entry(kk1).State = Microsoft.EntityFrameworkCore.EntityState.Modified; // await _context.SaveChangesAsync(); // return Ok(new { message = "Succesfuly added ! " }); // } // catch (Exception ex) // { // return BadRequest(new { Message = "Invalid Data" }); // throw ex; // } //} //else //{ RentCarCompany carC = new RentCarCompany(); carC.Adress = userModel.Address; carC.Description = userModel.Description; carC.CompanyName = userModel.CompanyName; applicationUser.Role = UserRole.CarAdmin; try { var result = await _userManager.CreateAsync(applicationUser, userModel.Email); var kk1 = await _userManager.FindByEmailAsync(userModel.Email); kk1.CarCompany = carC; _context.Entry(kk1).State = Microsoft.EntityFrameworkCore.EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(new { message = "Succesfuly added ! " })); } catch (Exception ex) { return(BadRequest(new { Message = "Invalid Data" })); throw ex; } //} }
void Awake() { instance = this; }
private void AddAdmin_Click(object sender, EventArgs e) { AddAdmin aa = new AddAdmin(); aa.Show(); }
public ActionResult AddAdmin(int?id, AddAdmin model) { if (!ModelState.IsValid) { if (id.Equals(null)) { return(RedirectToAction("AddAdmin")); } else { return(RedirectToAction("AddAdmin", id)); } } using (var _Context = new ApplicationContext()) { var CurrentUser = _Context.Users.Single(m => m.Email == User.Identity.Name).UserId; //for edit details if (!id.Equals(null)) { var data = _Context.Users.Single(m => m.UserId == id); var details = _Context.User_Details.Single(m => m.UserId == id); model.MaptoModel(data, details); data.Modified_By = CurrentUser; data.Modified_Date = DateTime.Now; details.Modified_date = DateTime.Now; _Context.SaveChanges(); return(RedirectToAction("ManageAdmin")); } //add new Admin else { var random = new Random(); int pwd = random.Next(100000, 999999); var create = _Context.Users; create.Add(new User { First_Name = model.FirstName, Last_Name = model.LastName, Email = model.Email, Password = pwd.ToString(), RoleId = 2, IsActive = true, Create_Date = DateTime.Now }); _Context.SaveChanges(); var newAdmin = _Context.Users.Single(m => m.Email == model.Email); var details = _Context.User_Details; details.Add(new User_Details { UserId = newAdmin.UserId, Phone_No_Country_Code = model.CountryCode, Phone_No = model.Phone, Address_Line1 = "", City = "", State = "", ZipCode = "", Country_Id = 1, }); _Context.SaveChanges(); // send email to admin string subject = "Welcome to Note - MarketPlace"; string body = "Hello " + model.FirstName + " " + model.LastName + "\\n\\n"; body += "You were added as a Admin in Note - MarketPlace \\n"; body += "Your Credentials are, \\n"; body += "Email: " + model.Email; body += "Password: "******"ManageAdmin")); } } }