Esempio n. 1
0
        public EmailResult Invitation(InvitationToken token)
        {
            // Setting up needed properties
            MailAttributes.From = new MailAddress("*****@*****.**", "Kawal Desa");
            MailAttributes.To.Add(new MailAddress(token.User.Email));
            MailAttributes.Subject = "Undangan bergabung dengan kawaldesa";
            MailAttributes.Priority = MailPriority.High;

            //Calling the view which form the email body
            return Email("Invitation", token);
        }
Esempio n. 2
0
        public static InvitationToken Create(DbContext db, String email, User inviter, 
            Organization organization, List<String> roles, List<Region> regions)
        {
            var UserStore = new CUserStore<User>(db);
            var UserManager = new UserManager<User>(UserStore);
            var RoleManager = new RoleManager<Role>(new CRoleStore<Role>(db));

            InvitationToken result = new InvitationToken();
            while(result.Token == null)
            {
                var token = GenerateToken();
                var exists = db.Set<InvitationToken>().Any(i => i.Token == token);
                if (!exists)
                    result.Token = token;
            }
            User user = new User();
            user.Email = email;
            user.UserName = email;
            user.fkOrganizationId = organization.Id;
            user.Id = Guid.NewGuid().ToString();
            user.Organization = organization;

            var userRes = UserManager.Create(user);
            if (!userRes.Succeeded)
                throw new ApplicationException(userRes.Errors.First());

            result.User = user;
            result.fkInviterId = inviter.Id;
            result.fkUserId = user.Id;
            db.Set<InvitationToken>().Add(result);
            db.SaveChanges();

            result.Inviter = inviter;
            result.User = user;

            foreach(var role in roles)
            {
                var res = UserManager.AddToRole(user.Id, role);
                Console.WriteLine(res);
            }
            foreach(var region in regions)
            {
                var scope = new UserScope
                {
                    fkUserId = user.Id,
                    fkRegionId = region.Id
                };
                db.Set<UserScope>().Add(scope);
            }
            db.SaveChanges();

            return result;
        }
Esempio n. 3
0
        public static InvitationToken Create(DbContext db, String email, User inviter, 
            Organization organization, List<String> roles, List<Region> regions)
        {
            var UserStore = new CUserStore<User>(db);
            var UserManager = new UserManager<User>(UserStore);
            var RoleManager = new RoleManager<Role>(new CRoleStore<Role>(db));

            InvitationToken result = new InvitationToken();
            result.Token = GenerateToken();
            User user = new User();
            user.Email = email;
            user.UserName = email;
            user.fkOrganizationId = organization.Id;
            user.Id = Guid.NewGuid().ToString();
            user.Organization = organization;

            UserManager.Create(user);

            result.User = user;
            result.fkInviterId = inviter.Id;
            result.fkUserId = user.Id;
            db.Set<InvitationToken>().Add(result);
            db.SaveChanges();

            result.Inviter = inviter;
            result.User = user;

            foreach(var role in roles)
            {
                var res = UserManager.AddToRole(user.Id, role);
                Console.WriteLine(res);
            }
            foreach(var region in regions)
            {
                var scope = new UserScope
                {
                    fkUserId = user.Id,
                    fkRegionId = region.Id
                };
                db.Set<UserScope>().Add(scope);
            }
            db.SaveChanges();

            return result;
        }
        public static InvitationToken Create(DbContext db, String email, User inviter,
                                             Organization organization, List <String> roles, List <Region> regions)
        {
            var UserStore   = new CUserStore <User>(db);
            var UserManager = new UserManager <User>(UserStore);
            var RoleManager = new RoleManager <Role>(new CRoleStore <Role>(db));


            InvitationToken result = new InvitationToken();

            while (result.Token == null)
            {
                var token  = GenerateToken();
                var exists = db.Set <InvitationToken>().Any(i => i.Token == token);
                if (!exists)
                {
                    result.Token = token;
                }
            }
            User user = new User();

            user.Email            = email;
            user.UserName         = email;
            user.fkOrganizationId = organization.Id;
            user.Id           = Guid.NewGuid().ToString();
            user.Organization = organization;

            var userRes = UserManager.Create(user);

            if (!userRes.Succeeded)
            {
                throw new ApplicationException(userRes.Errors.First());
            }

            result.User        = user;
            result.fkInviterId = inviter.Id;
            result.fkUserId    = user.Id;
            db.Set <InvitationToken>().Add(result);
            db.SaveChanges();

            result.Inviter = inviter;
            result.User    = user;

            foreach (var role in roles)
            {
                var res = UserManager.AddToRole(user.Id, role);
                Console.WriteLine(res);
            }
            foreach (var region in regions)
            {
                var scope = new UserScope
                {
                    fkUserId   = user.Id,
                    fkRegionId = region.Id
                };
                db.Set <UserScope>().Add(scope);
            }
            db.SaveChanges();

            return(result);
        }