public async Task <IActionResult> AssignRoleToUser(int UserID, int RoleID)
        {
            var role = from roles in _context.Roles
                       where roles.RoleID == RoleID
                       select roles;
            var user = from users in _context.Users
                       where users.UserID == UserID
                       select users;

            var userDisplay = from users in _context.UserRoles
                              where users.RoleID == RoleID
                              select users.User;
            UserRole userRole = new UserRole();

            userRole.UserID = UserID;
            userRole.User   = _context.Users.Find(UserID);
            userRole.RoleID = RoleID;
            userRole.Role   = _context.Roles.Find(RoleID);
            _context.Entry(userRole).State = EntityState.Added;
            //TODO catch exception from them already demoing for the module
            if (ModelState.IsValid)
            {
                _context.UserRoles.Add(userRole);
                await _context.SaveChangesAsync();

                //TODO query to find correct users
                return(View("UserDetails", _context.Users.Find(UserID)));
            }
            return(View("UserDetails", _context.Users.Find(UserID)));
        }
        public async Task <IActionResult> ProposeDemonstrator(int UserID, int ModuleID)
        {
            var module = from modules in _context.Modules
                         where modules.ModuleID == ModuleID
                         select modules;
            var user = from users in _context.Users
                       where users.UserID == UserID
                       select users;

            var userDisplay = from users in _context.ModuleUsers
                              where users.ModuleID == ModuleID
                              select users.User;
            Proposal proposal = new Proposal();

            proposal.UserID   = UserID;
            proposal.User     = _context.Users.Find(UserID);
            proposal.ModuleID = ModuleID;
            proposal.Module   = _context.Modules.Find(ModuleID);
            proposal.Approved = false;
            _context.Entry(proposal).State = EntityState.Added;
            //TODO catch exception from them already demoing for the module
            if (ModelState.IsValid)
            {
                _context.Proposal.Add(proposal);
                await _context.SaveChangesAsync();

                //TODO query to find correct users
                return(View("ModuleDemonstrators", Tuple.Create(_context.Modules.Find(ModuleID), userDisplay.ToList())));
            }
            return(View("ModuleDemonstrators", Tuple.Create(_context.Modules.Find(ModuleID), userDisplay.ToList())));
        }
Beispiel #3
0
        /// <summary>
        /// Search for the allocation at a certain time for the senior team.
        /// </summary>
        /// <param name="time">The time to search for in seconds since UNIX epoch.</param>
        /// <returns>The senior team allocation at the time if it exists, null otherwise.</returns>
        public SeniorTeam GetPastSeniorTeam(long time)
        {
            using (var context = new AllocationContext(_dbOptions))
            {
                var allocations = context.TeamAllocations
                                  .Include(t => t.Positions)
                                  .ThenInclude(p => p.StaffPosition)
                                  .Where(p => p.Type == Model.TeamType.Senior)
                                  .Where(p => time >= p.Time);

                var allocation = allocations.FirstOrDefault(p => p.Time == allocations.Max(q => q.Time));
                if (allocation == null)
                {
                    return(null);
                }
                else
                {
                    foreach (var pos in allocation.Positions.Where(p => p.StaffPosition is KnownStaffPosition))
                    {
                        context.Entry(pos.StaffPosition as KnownStaffPosition)
                        .Reference(sp => sp.StaffMember)
                        .Load();
                    }

                    return(ModelConverter.SeniorTeamFromModel(allocation));
                }
            }
        }
Beispiel #4
0
        public async Task <IActionResult> LogHoursFinal(int UserID, int ModuleID, double hoursWorked, double hoursAllocated)
        {
            ModuleUser moduleUser = _context.ModuleUsers.Find(ModuleID, UserID);

            moduleUser.HoursWorked           = moduleUser.HoursWorked + hoursWorked;
            _context.Entry(moduleUser).State = EntityState.Added;
            //TODO catch exception from them already demoing for the module
            if (ModelState.IsValid)
            {
                _context.ModuleUsers.Update(moduleUser);
                await _context.SaveChangesAsync();

                //Redirects to the "Users" action of the controller "User"
                return(RedirectToAction("Users", "User"));
            }
            return(RedirectToAction("Users", "User"));
        }
Beispiel #5
0
        /// <summary>
        /// Gets the latest allocation for a team from the database.
        /// </summary>
        /// <param name="type">The team queried.</param>
        /// <param name="context">The database context.</param>
        /// <returns>The latest allocation for the team.</returns>
        /// <remarks>There must be an allocation for the team.</remarks>
        private TeamAllocation GetLatestAllocation(Model.TeamType team, AllocationContext context)
        {
            if (!context.TeamAllocations.Where(t => t.Type == team).Any())
            {
                throw new Exception(string.Format("No allocations for team {0}.", team));
            }

            var allocation = context.TeamAllocations
                             .Include(t => t.Positions)
                             .ThenInclude(p => p.StaffPosition)
                             .Single(p => p.Type == team &&
                                     p.Time == context.TeamAllocations
                                     .Where(q => q.Type == team)
                                     .Max(q => q.Time));

            foreach (var pos in allocation.Positions.Select(p => p.StaffPosition).OfType <KnownStaffPosition>())
            {
                context.Entry(pos)
                .Reference(sp => sp.StaffMember)
                .Load();
            }

            return(allocation);
        }