public ConferenceDelegateRole AddNonGovernmentSeat(string name, string iso, string authTypeName = "Participant")
    {
        var committee = _dbContext.Committees
                        .Include(n => n.Conference)
                        .FirstOrDefault(n => n.CommitteeId == _committeeId);

        var participantAuth = _dbContext.ConferenceRoleAuthorizations.FirstOrDefault(n =>
                                                                                     n.RoleAuthName == authTypeName && n.Conference.ConferenceId == committee.Conference.ConferenceId);

        var role = new ConferenceDelegateRole()
        {
            Committee          = committee,
            Conference         = committee.Conference,
            ConferenceRoleAuth = participantAuth,
            RoleName           = name,
            DelegateCountry    = null,
            RoleFullName       = name,
            DelegateType       = "NA",
            RoleShort          = iso,
            RoleSecret         = Util.IdGenerator.SHA512($"{committee.CommitteeId}{name}").Substring(0, 32)
        };

        _dbContext.Delegates.Add(role);
        _dbContext.SaveChanges();
        return(role);
    }
Example #2
0
        public CreateConferenceResponse CreateConference(CreateConferenceRequest request, ClaimsPrincipal claim)
        {
            var response = new CreateConferenceResponse();
            var user     = context.Users.FirstOrDefault(n => n.UserName == claim.Identity.Name);

            if (user == null)
            {
                response.AddNoPermissionError("You are not allowed to create a conference.");
                return(response);
            }

            var project = context.Projects.FirstOrDefault(n => n.ProjectId == request.ProjectId);

            if (project == null)
            {
                response.AddInvalidDataError("The Project was not found.", nameof(request.ProjectId));
                return(response);
            }

            // Create the conference
            var conference = new Conference()
            {
                Name              = request.Name,
                FullName          = request.FullName,
                ConferenceShort   = request.ConferenceShort,
                ConferenceProject = project,
                CreationDate      = DateTime.UtcNow,
                CreationUser      = user,
                StartDate         = request.StartDate,
                EndDate           = request.EndDate
            };

            var easyId = Util.IdGenerator.AsPrimaryKey(request.ConferenceShort);

            if (context.Conferences.All(n => n.ConferenceId != easyId))
            {
                conference.ConferenceId = easyId;
            }

            //if (DateTime.TryParse(request.StartDate, out DateTime start))
            //    conference.StartDate = start;

            //if (DateTime.TryParse(request.EndDate, out DateTime end))
            //    conference.EndDate = end;

            context.Conferences.Add(conference);


            CreateDefaultConferenceAuths(conference);

            context.SaveChanges();

            response.ConferenceId = conference.ConferenceId;

            return(response);
        }
Example #3
0
    public void TestCreateOrganization()
    {
        var organization = new Organization()
        {
            OrganizationName  = "Deutsche Model United Nations e.V.",
            OrganizationShort = "DMUN e.V."
        };

        _context.Organizations.Add(organization);
        _context.SaveChanges();
        Assert.AreEqual(1, _context.Organizations.Count());
    }
Example #4
0
    public void TestRemovingAnOrganization()
    {
        var organization = new Organization();

        _context.Organizations.Add(organization);
        _context.SaveChanges();

        Assert.AreEqual(1, _context.Organizations.Count());

        _context.Organizations.Remove(organization);
        _context.SaveChanges();
        Assert.AreEqual(1, _context.Organizations.Count(n => n.IsDeleted));
    }
Example #5
0
    public OrganizationMember AddUserIntoRole(string username, string roleName)
    {
        var user = this._dbContext.Users.FirstOrDefault(n => n.NormalizedUserName == username.ToUpper());

        if (user == null)
        {
            throw new UserNotFoundException($"No user with the username {username} was found.");
        }

        var role = this._dbContext.OrganizationRoles.FirstOrDefault(n => n.Organization.OrganizationId == _organizationId &&
                                                                    n.RoleName == roleName);

        if (role == null)
        {
            throw new OrganizationRoleNotFoundException($"No Role with the name {roleName} was found for the organization {this._organizationId}");
        }

        var membership = new OrganizationMember()
        {
            JoinedDate   = DateTime.Now,
            Organization = _dbContext.Organizations.Find(_organizationId),
            Role         = role,
            User         = user
        };

        _dbContext.OrganizationMembers.Add(membership);
        _dbContext.SaveChanges();
        return(membership);
    }
Example #6
0
    public Conference AddConference(Action <ConferenceOptionsBuilder> options)
    {
        var builder = new ConferenceOptionsBuilder(_dbContext);

        options(builder);
        _dbContext.Conferences.Add(builder.Conference);
        _dbContext.SaveChanges();
        return(builder.Conference);
    }
Example #7
0
    public Project AddProject(Action <ProjectOptionsBuilder> options)
    {
        var builder = new ProjectOptionsBuilder(_dbContext);

        options(builder);
        var project = builder.Project;

        _dbContext.Projects.Add(project);
        _dbContext.SaveChanges();
        return(project);
    }
        public ListOfSpeakers CreateList(string id = null)
        {
            var databaseModel = new ListOfSpeakers();

            if (id != null)
            {
                databaseModel.ListOfSpeakersId = id;
            }
            dbContext.ListOfSpeakers.Add(databaseModel);
            dbContext.SaveChanges();
            return(databaseModel);
        }
Example #9
0
    public static int SetupBaseRoles(this MunityContext context)
    {
        if (!context.Roles.Any())
        {
            foreach (var munityRole in BaseData.DefaultAuthorizations.UserRoles)
            {
                context.Roles.Add(munityRole);
            }
        }

        return(context.SaveChanges());
    }
        public CreatedPageResult AddPage(string conferenceId, int?parentItemId)
        {
            MUNity.Database.Models.Website.ConferenceWebMenuEntry parent = null;
            if (parentItemId != null)
            {
                parent = _context.ConferenceWebMenuEntries.Find(parentItemId);
            }

            var page = new MUNity.Database.Models.Website.ConferenceWebPage()
            {
                Conference     = _context.Conferences.Find(conferenceId),
                CreationDate   = DateTime.Now,
                IsIndexPage    = false,
                LastUpdateDate = DateTime.Now,
                Title          = "New Page"
            };

            var menuItem = new MUNity.Database.Models.Website.ConferenceWebMenuEntry()
            {
                Conference   = _context.Conferences.Find(conferenceId),
                Parent       = parent,
                TargetedPage = page,
                Title        = "New Page"
            };

            _context.ConferenceWebMenuEntries.Add(menuItem);
            _context.ConferenceWebPages.Add(page);
            var recaff = _context.SaveChanges();

            var result = new CreatedPageResult();

            if (recaff > 0)
            {
                result.Success    = true;
                result.PageId     = page.ConferenceWebPageId;
                result.MenuItemId = menuItem.ConferenceWebMenuEntryId;
            }

            return(result);
        }
Example #11
0
        public async Task <CreateDelegationResponse> CreateDelegationAsync(CreateDelegationRequest request, ClaimsPrincipal claim)
        {
            var response  = new CreateDelegationResponse();
            var isAllowed = await authService.IsUserAllowedToEditConference(request.ConferenceId, claim);

            if (!isAllowed)
            {
                response.AddNoPermissionError();
                return(response);
            }

            var conference = context.Conferences.FirstOrDefault(n => n.ConferenceId == request.ConferenceId);

            if (conference == null)
            {
                response.AddNotFoundError(nameof(request.ConferenceId));
                return(response);
            }

            var delegation = new Delegation()
            {
                Conference      = conference,
                DelegationShort = request.DelegationShort,
                FullName        = request.DelegationFullName,
                Name            = request.DelegationName
            };

            string easyId = conference.ConferenceId + "-" + Util.IdGenerator.AsPrimaryKey(request.DelegationShort);

            if (context.Delegations.All(n => n.DelegationId != easyId))
            {
                delegation.DelegationId = easyId;
            }

            context.Delegations.Add(delegation);
            context.SaveChanges();

            return(response);
        }
Example #12
0
    public void Setup()
    {
        // Datenbank für den Test erzeugen und falls vorhanden erst einmal leeren und neu erstellen!
        var optionsBuilder = new DbContextOptionsBuilder <MunityContext>();

        optionsBuilder.UseSqlite("Data Source=test_conferenceRoles.db");
        _context = new MunityContext(optionsBuilder.Options);
        _context.Database.EnsureDeleted();
        _context.Database.EnsureCreated();

        organization = new Organization()
        {
            OrganizationName  = "Test Organization",
            OrganizationShort = "TO"
        };
        project = new Project()
        {
            ProjectName         = "Test Project",
            ProjectOrganization = organization,
            ProjectShort        = "TP",
        };
        conference = new Conference()
        {
            ConferenceProject = project,
            ConferenceShort   = "TC",
            CreationDate      = DateTime.Now,
            EndDate           = new DateTime(2021, 1, 4),
            StartDate         = new DateTime(2021, 1, 1),
            FullName          = "Test Conference",
            Name = "Test Conference"
        };
        var committee = new Committee()
        {
            Article        = "die",
            CommitteeShort = "GV",
            Conference     = conference,
            FullName       = "Generalversammlung",
            Name           = "Generalversammlung"
        };

        _context.Organizations.Add(organization);
        _context.Projects.Add(project);
        _context.Conferences.Add(conference);
        _context.Committees.Add(committee);
        _context.SaveChanges();
    }
Example #13
0
    public void TestCanCreateInstalledSetting()
    {
        _context.Settings.Add(new MunitySetting()
        {
            SetttingName = "Installed",
            SettingValue = "1",
            ChangeDate   = new DateTime(2021, 1, 1, 12, 0, 0),
            SetBy        = null
        });
        _context.SaveChanges();
        var recallSetting = _context.Settings.FirstOrDefault(n => n.SetttingName == "Installed");

        Assert.NotNull(recallSetting);
        Assert.AreEqual("Installed", recallSetting.SetttingName);
        Assert.AreEqual("1", recallSetting.SettingValue);
        Assert.AreEqual(new DateTime(2021, 1, 1, 12, 0, 0), recallSetting.ChangeDate);
        Assert.IsNull(recallSetting.SetBy);
    }
Example #14
0
    public void TestCreateTeamRoleProjectLeader()
    {
        var leaderAuth = new ConferenceRoleAuth()
        {
            Conference = conference,
            CanEditConferenceSettings = true,
            CanEditParticipations     = true,
            CanSeeApplications        = true,
            PowerLevel   = 1,
            RoleAuthName = "Project-Owner"
        };

        _context.ConferenceRoleAuthorizations.Add(leaderAuth);

        var leaderRoleGroup = new TeamRoleGroup()
        {
            FullName           = "die Projektleitung",
            Name               = "Projektleitung",
            TeamRoleGroupShort = "PL",
            GroupLevel         = 1
        };

        _context.TeamRoleGroups.Add(leaderRoleGroup);

        var leaderRole = new ConferenceTeamRole()
        {
            Conference         = conference,
            IconName           = "pl",
            RoleFullName       = "Projektleiter",
            ConferenceRoleAuth = leaderAuth,
            RoleName           = "Projektleiter",
            RoleShort          = "PL",
            TeamRoleGroup      = leaderRoleGroup,
            TeamRoleLevel      = 1,
        };

        _context.ConferenceTeamRoles.Add(leaderRole);
        _context.SaveChanges();

        var leaderRoleCallback = _context.ConferenceTeamRoles.FirstOrDefault();

        Assert.NotNull(leaderRoleCallback);
        Assert.AreEqual(1, _context.ConferenceRoleAuthorizations.Count());
        Assert.AreEqual(1, _context.ConferenceTeamRoles.Count());
        Assert.AreEqual(1, _context.TeamRoleGroups.Count());
        Assert.AreEqual("TeamRole", leaderRoleCallback.RoleType);
    }
Example #15
0
    /// <summary>
    /// Adds the countries that are given to the Database. If a country already has the given name it
    /// will just update the country.
    /// </summary>
    /// <param name="context"></param>
    /// <param name="countries"></param>
    /// <returns></returns>
    public static int AddBaseCountries(this MunityContext context, IEnumerable <Country> countries)
    {
        foreach (var country in countries)
        {
            var matchingCountry = context.Countries.Include(n => n.Translations).FirstOrDefault(n =>
                                                                                                n.Name == country.Name);
            if (matchingCountry != null)
            {
                // Update the country
                matchingCountry.FullName = country.FullName;
                matchingCountry.Iso      = country.Iso;
                if (country.Continent != EContinent.NotSet)
                {
                    matchingCountry.Continent = country.Continent;
                }

                if (country.Translations.Count > 0)
                {
                    foreach (var translation in country.Translations)
                    {
                        var foundTranslation =
                            matchingCountry.Translations.FirstOrDefault(n =>
                                                                        n.LanguageCode == translation.LanguageCode);
                        if (foundTranslation != null)
                        {
                            foundTranslation.TranslatedName     = translation.TranslatedName;
                            foundTranslation.TranslatedFullName = translation.TranslatedFullName;
                        }
                    }
                }
            }
            else
            {
                context.Countries.Add(country);
            }
        }

        return(context.SaveChanges());
    }
Example #16
0
        public async Task <bool> SetDelegateRoleApplicationState(int roleId, EApplicationStates state, ClaimsPrincipal claim)
        {
            var roleWithConference = _context.Delegates
                                     .Include(n => n.Conference)
                                     .FirstOrDefault(n => n.RoleId == roleId);

            if (roleWithConference?.Conference == null)
            {
                return(false);
            }

            var isAllowed = await _authService.IsUserAllowedToEditConference(roleWithConference.Conference.ConferenceId, claim);

            if (!isAllowed)
            {
                return(false);
            }

            roleWithConference.ApplicationState = state;
            _context.SaveChanges();
            return(true);
        }
Example #17
0
        public Organization CreateOrganization(string name, string shortName, MunityUser user)
        {
            var organization = new Organization()
            {
                OrganizationName  = name,
                OrganizationShort = shortName,
            };

            var easyId = Util.IdGenerator.AsPrimaryKey(shortName);

            if (context.Organizations.All(n => n.OrganizationId != easyId))
            {
                organization.OrganizationId = easyId;
            }

            var orgaAdminRole = new OrganizationRole()
            {
                CanCreateProject = true,
                CanManageMembers = true,
                CanCreateRoles   = true,
                RoleName         = "Admin",
                Organization     = organization
            };

            var membership = new OrganizationMember()
            {
                JoinedDate   = DateTime.Now,
                Organization = organization,
                Role         = orgaAdminRole,
                User         = user
            };

            context.Organizations.Add(organization);
            context.OrganizationRoles.Add(orgaAdminRole);
            context.OrganizationMembers.Add(membership);
            context.SaveChanges();
            return(organization);
        }
Example #18
0
        public TeamRoleGroup AddTeamRoleGroup(Action <ITeamRoleBuilder> options)
        {
            var conference = _dbContext.Conferences.Find(_conferenceId);

            if (conference == null)
            {
                throw new ConferenceNotFoundException($"No conference found for {_conferenceId}");
            }

            var builder = new TeamRoleGroupBuilder();

            options(builder);
            conference.TeamRoleGroups.Add(builder.Group);
            if (builder.Group.TeamRoles.Count > 0)
            {
                foreach (var conferenceTeamRole in builder.Group.TeamRoles)
                {
                    conferenceTeamRole.Conference = conference;
                }
            }
            _dbContext.SaveChanges();
            return(builder.Group);
        }
Example #19
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");
            //ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid && Input.AcceptedAGB)
            {
                var userFound = await _userManager.FindByEmailAsync(Input.Email);

                if (userFound != null)
                {
                    if (userFound.IsShadowUser)
                    {
                        userFound.UserName = Input.Username;
                        userFound.Forename = Input.Forename;
                        userFound.Lastname = Input.Lastname;
                        await _userManager.RemovePasswordAsync(userFound);

                        await _userManager.ChangePasswordAsync(userFound, String.Empty, Input.Password);

                        _dbContext.Update(userFound);
                        _dbContext.SaveChanges();
                        await _signInManager.SignInAsync(userFound, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                    _logger.LogWarning($"User already exisits and was not a shadow user: {Input.Username}");
                }
                else
                {
                    var user = new MunityUser
                    {
                        UserName         = Input.Username,
                        Email            = Input.Email,
                        RegistrationDate = DateTime.UtcNow,
                        Birthday         = new DateOnly(Input.BirthdayYear, Input.BirthdayMonth, Input.BirthdayDay),
                        Forename         = Input.Forename,
                        Lastname         = Input.Lastname
                    };

                    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>.");

                        //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);
                    }
                }
            }
            else
            {
                Console.WriteLine("AGB not accepted!");
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Example #20
0
        public ResaElement CreateResolution()
        {
            var element = new ResaElement();

            _context.Resolutions.Add(element);
            _context.SaveChanges();
            _logger.LogInformation("New Resolution with id {0} created.", element.ResaElementId);
            return(element);
        }
Example #21
0
 public DelegationApplication Submit()
 {
     _context.DelegationApplications.Add(this.application);
     _context.SaveChanges();
     return(application);
 }
Example #22
0
    private Organization CreateTestOrganization()
    {
        var organization = new Organization()
        {
            OrganizationName  = "Deutsche Model United Nations e.V.",
            OrganizationShort = "DMUN e.V."
        };

        _context.Organizations.Add(organization);
        _context.SaveChanges();
        return(organization);
    }
Example #23
0
 public Delegation Save()
 {
     _context.Delegations.Add(Delegation);
     _context.SaveChanges();
     return(Delegation);
 }