Пример #1
0
        public async Task <IActionResult> Create([Bind("id,name")] RoleModel roleModel)
        {
            if (await extractUser())
            {
                if (user.role.name == "CEO")
                {
                    if (ModelState.IsValid)
                    {
                        _context.Add(roleModel);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    return(View(roleModel));
                }
                else
                {
                    return(View("NoPermission"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "LogIn"));
            }
        }
Пример #2
0
        public async Task <IActionResult> Approve(int?id)
        {
            if (await extractUser())
            {
                HospitalLeaveModel application = await _context.HospitalLeaves.FindAsync(id);

                user = await _context.Users.Include(u => u.leadedTeam).ThenInclude(u => u.devs).FirstOrDefaultAsync(u => u.id == user.id);

                if (user.role.name == "CEO" ||
                    (user.role.name == "Team Lead" &&
                     user.leadedTeam.devs.Any(d => d.hospitalLeaves.Contains(application))))
                {
                    application.approved = true;
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(IndexDisapproved)));
                }

                else
                {
                    return(View("NoPermission"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "LogIn"));
            }
        }
Пример #3
0
        public async Task <IActionResult> RemoveFromTeam(int?userId, int?teamId)
        {
            if (await extractUser())
            {
                if (userId == null || teamId == null)
                {
                    return(NotFound());
                }

                UserModel u = await _context.Users.Where(u => u.id == userId).Include(u => u.team).FirstOrDefaultAsync();

                var teamModel = await _context.Teams.Include(t => t.devs).Include(t => t.project).Include(t => t.teamLeader)
                                .FirstOrDefaultAsync(m => m.id == teamId);

                if (teamModel == null)
                {
                    return(NotFound());
                }

                teamModel.devs.Remove(u);
                u.team = null;
                await _context.SaveChangesAsync();

                //TODO: Refaactor
                return(await TeamDetailsView(teamModel));
            }
            else
            {
                return(RedirectToAction("Index", "LogIn"));
            }
        }
Пример #4
0
        public async Task <IActionResult> ChangeUsername(string username)
        {
            if (await extractIdAndUser())
            {
                if (!String.IsNullOrEmpty(username))
                {
                    if (!_context.Users.Select(u => u.username).Contains(username))
                    {
                        user.username = username;
                        await _context.SaveChangesAsync();

                        return(await userView(user));
                    }
                    else
                    {
                        ViewData["Message"] = "This username is taken or it is the same!";
                        return(await userView(user));
                    }
                }
                else
                {
                    ViewData["Message"] = "Username is required!";
                    return(await userView(user));
                }
            }
            else
            {
                return(RedirectToAction("Index", "LogIn"));
            }
        }
        public async Task <IActionResult> Index([Bind("username,firstName,lastName,password,confirmPassword")] UserModel userModel)
        {
            if (ModelState.IsValid)
            {
                //TODO async
                if (!_context.Users.Select(u => u.username).Contains(userModel.username))
                {
                    userModel.role = await _context.Roles.Where(r => r.name == "Unassigned").FirstOrDefaultAsync();

                    userModel.password = Utilities.HashFunctions.HashPassword(userModel.password);
                    _context.Add(userModel);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", "LogIn"));
                }
                else
                {
                    ViewData["Error message"] = "This username is taken!";
                    return(View());
                }
            }
            else
            {
                ViewData["Error message"] = "One or more field has data that doesn't match the criteria for it!";
                return(View());
            }
        }
Пример #6
0
        public async Task <IActionResult> RemoveFromProject(int?projectId, int?teamId)
        {
            if (await extractUser())
            {
                if (user.role.name == "CEO")
                {
                    if (projectId == null || teamId == null)
                    {
                        return(NotFound());
                    }

                    TeamModel teamForRemoval = await _context.Teams.FirstAsync(t => t.id == teamId);

                    ProjectModel projectModel = await _context.Projects.Include(p => p.workingTeams).ThenInclude(t => t.teamLeader)
                                                .FirstOrDefaultAsync(m => m.id == projectId);

                    if (projectModel == null)
                    {
                        return(NotFound());
                    }

                    projectModel.workingTeams.Remove(teamForRemoval);
                    teamForRemoval.project = null;
                    await _context.SaveChangesAsync();

                    //TODO: Refaactor
                    return(await ProjectDetailsView(projectModel));
                }
                else
                {
                    return(View("NoPermission"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "LogIn"));
            }
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("id,username,firstName,lastName,password")] UserModel userModel)
        {
            if (await extractUser())
            {
                if (user.role.name == "CEO")
                {
                    ModelState.Remove("confirmPassword");
                    if (ModelState.IsValid)
                    {
                        userModel.role = await _context.Roles.Where(r => r.name == "Unassigned").FirstOrDefaultAsync();

                        userModel.password = Utilities.HashFunctions.HashPassword(userModel.password);
                        _context.Add(userModel);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    return(View(userModel));
                }
                else
                {
                    return(View("NoPermission"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "LogIn"));
            }
        }