Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
        private void createAdminToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            AddAdmin add = new AddAdmin();

            panel1.Controls.Add(add);
        }
Ejemplo n.º 3
0
 /// <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());
     }
 }
Ejemplo n.º 6
0
 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);
     }
 }
Ejemplo n.º 7
0
 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());
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        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());
        }
Ejemplo n.º 12
0
 /// <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());
     }
 }
Ejemplo n.º 13
0
 /// <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));
        }
Ejemplo n.º 15
0
        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!!!!");
            }
        }
Ejemplo n.º 16
0
 public AddAdminViewModel(AddAdmin addAdminOpen)
 {
     addAdmin      = addAdminOpen;
     seerviceAdmin = new SeerviceAdmin();
     Admin         = new vwAdmin();
 }
Ejemplo n.º 17
0
        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;
            }
            //}
        }
Ejemplo n.º 18
0
 void Awake()
 {
     instance = this;
 }
Ejemplo n.º 19
0
        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"));
                }
            }
        }