예제 #1
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid) {
                TempData["RegisterModel"] = model;
                TempData["Errors"] = ModelState.Values.SelectMany(v => v.Errors).ToList();

                return RedirectToAction("Register", "Auth");
            }

            IProfileService service = ProfileService.GetInstance<ProfileRepository>();
            // Verifies if the emails is not being used
            Whiteboard.DataAccess.Models.Profile profile = service.Get(model.Email);
            if (profile != null) {
                ModelState.AddModelError("ModelExists", "Email already exists.");
                TempData["RegisterModel"] = model;
                TempData["Errors"] = ModelState.Values.SelectMany(v => v.Errors).ToList();

                return RedirectToAction("Register", "Auth");
            }
            IRoleProfileService roleProfileService = RoleProfileService.GetInstance<RoleProfileRepository>();
            // Sets the default image for profile
            var profileInsert = model.Profile;
            profileInsert.PictureUrl = "user.png";
            profile = service.Insert(profileInsert);

            // Creates a default role for the new profile
            RoleProfile roleProfile = new RoleProfile();
            roleProfile.ProfileId = profile.Id;
            roleProfile.RoleId = (int)Role.Roles.School;
            roleProfileService.Insert(roleProfile);

            return RedirectToAction("Login", "Auth");
        }
예제 #2
0
        private void RoleProfileGenerator()
        {
            RoleProfile roleProfileSchool = new RoleProfile();
            roleProfileSchool.ProfileId = 1;
            roleProfileSchool.RoleId = (int)Role.Roles.School;

            RoleProfile roleProfileTeacher = new RoleProfile();
            roleProfileTeacher.ProfileId = 2;
            roleProfileTeacher.RoleId = (int)Role.Roles.Teacher;

            RoleProfile roleProfileStudent = new RoleProfile();
            roleProfileStudent.ProfileId = 3;
            roleProfileStudent.RoleId = (int)Role.Roles.Student;

            RoleProfile rp4 = new RoleProfile();
            rp4.ProfileId = 4;
            rp4.RoleId = (int)Role.Roles.Teacher;

            RoleProfile rp5 = new RoleProfile();
            rp5.ProfileId = 5;
            rp5.RoleId = (int)Role.Roles.Student;

            RoleProfile rp6 = new RoleProfile();
            rp6.ProfileId = 6;
            rp6.RoleId = (int)Role.Roles.School;

            RoleProfile rp7 = new RoleProfile();
            rp7.ProfileId = 7;
            rp7.RoleId = (int)Role.Roles.Student;

            context.RoleProfiles.Add(roleProfileSchool);
            context.RoleProfiles.Add(roleProfileTeacher);
            context.RoleProfiles.Add(roleProfileStudent);
            context.RoleProfiles.Add(rp4);
            context.RoleProfiles.Add(rp5);
            context.RoleProfiles.Add(rp6);
            context.RoleProfiles.Add(rp7);
        }