Esempio n. 1
0
        public bool AddMember(Member NewMember)
        {
            Members MemberManager = new Members();
            bool    confirmation;

            confirmation = MemberManager.AddMember(NewMember);
            return(confirmation);
        }
Esempio n. 2
0
 protected void Btn_Add_New_Click(object sender, EventArgs e)
 {
     try
     {
         Boolean fileOK = false;
         String  path   = Server.MapPath("~/img/Members/");
         if (Passport.HasFile)
         {
             String   fileExtension     = System.IO.Path.GetExtension(Passport.FileName).ToLower();
             String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
             for (int i = 0; i < allowedExtensions.Length; i++)
             {
                 if (fileExtension == allowedExtensions[i])
                 {
                     fileOK = true;
                 }
             }
         }
         if (fileOK)
         {
             try
             {
                 // Save to Images folder.
                 Passport.PostedFile.SaveAs(path + Passport.FileName);
                 // Save to Images/Thumbs folder.
                 Passport.PostedFile.SaveAs(path + Passport.FileName);
             }
             catch (Exception ex)
             {
                 AddStatus.Text = ex.Message;
             }
             // Add product data to DB.
             Members members    = new Members();
             bool    addSuccess = members.AddMember(Email.Text, Firstname.Text, Lastname.Text, Othername.Text, Address.Text, Gender.SelectedValue,
                                                    MaritalStatus.SelectedValue, Qualification.Text, Position.Text, DateTime.Parse(DateOfBirth.Text), PhoneNumber.Text, StateOfOrigin.Text,
                                                    Passport.FileName, Membership.SelectedValue, "N/A", "N/A", "N/A");
             if (addSuccess)
             {
                 // Reload the page.
                 string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                 Response.Redirect(pageUrl + "?MemberAction=add");
             }
             else
             {
                 AddStatus.Text = "Unable to add new member to database.";
             }
         }
         else
         {
             AddStatus.Text = "Unable to accept file type.";
         }
     }
     catch (Exception ex)
     {
         AddStatus.Text = ex.Message;
     }
 }
Esempio n. 3
0
        public ActionResult Add(MemberAddModel m)
        {
            if (Members.GmailExists(m.Gmail))
            {
                return(RedirectToAction("Add"));
            }

            Members.AddMember(m.Gmail, m.Password, m.Name, m.Surname, Int32.Parse(m.RoleIdString), m.Date);

            return(RedirectToAction("AllMembers"));
        }
 public bool AddMember(Member m)
 {
     return(members.AddMember(m));
 }
Esempio n. 5
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var member        = new Members();
            var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>();

            //var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
            //IdentityResult result = manager.Create(user, Password.Text);
            //if (result.Succeeded)
            //{
            //    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
            //    //string code = manager.GenerateEmailConfirmationToken(user.Id);
            //    //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
            //    //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");
            //    member.AddMember(Email.Text,"","","","","","","","",DateTime.Now.Date,"","","","","","","Undecided");
            //    signInManager.SignIn( user, isPersistent: false, rememberBrowser: false);
            //    IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            //}
            //else
            //{
            //    ErrorMessage.Text = result.Errors.FirstOrDefault();
            //}


            // Access the application context and create result variables.
            Models.ApplicationDbContext context = new ApplicationDbContext();
            IdentityResult IdRoleResult;
            IdentityResult IdUserResult;

            // Create a RoleStore object by using the ApplicationDbContext object.
            // The RoleStore is only allowed to contain IdentityRole objects.
            var roleStore = new RoleStore <IdentityRole>(context);

            // Create a RoleManager object that is only allowed to contain IdentityRole objects.
            // When creating the RoleManager object, you pass in (as a parameter) a new RoleStore object.
            var roleMgr = new RoleManager <IdentityRole>(roleStore);

            // Then, you create the "Administrator" role if it doesn't already exist.
            if (!roleMgr.RoleExists("Member"))
            {
                IdRoleResult = roleMgr.Create(new IdentityRole("Member"));
                if (!IdRoleResult.Succeeded)
                {
                    // Handle the error condition if there's a problem creating the RoleManager object.
                }
            }

            // Create a UserManager object based on the UserStore object and the ApplicationDbContext
            // object. Note that you can create new objects and use them as parameters in
            // a single line of code, rather than using multiple lines of code, as you did
            // for the RoleManager object.
            var userMgr = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
            var appUser = new ApplicationUser()
            {
                UserName = Email.Text,
            };

            IdUserResult = userMgr.Create(appUser, Password.Text);

            // If the new "Admin" user was successfully created,
            // add the "Admin" user to the "Administrator" role.
            if (IdUserResult.Succeeded)
            {
                IdUserResult = userMgr.AddToRole(appUser.Id, "Member");
                if (!IdUserResult.Succeeded)
                {
                    // Handle the error condition if there's a problem adding the user to the role.
                }
                member.AddMember(Email.Text, "", "", "", "", "", "", "", "", DateTime.Now.Date, "", "", "", "", "", "", "Undecided");
                signInManager.SignIn(appUser, isPersistent: false, rememberBrowser: false);
                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else
            {
                // Handle the error condition if there's a problem creating the new user.
                ErrorMessage.Text = IdUserResult.Errors.FirstOrDefault();
            }
        }