Beispiel #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            int fileid = Int32.Parse(Request.Form["fileid"]);

            string username = HttpContext.Session.GetString("username");

            //Firstly we need to find wether the user is a member of a team leader
            //It is so that we can find his/her team
            //1. Team leader
            AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1));

            TeamPresentation teamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamPresentationId.Equals(fileid) && tp.EventID.Equals(app.EventID));

            if (teamPresentation == null)
            {
                Message = "There was an error with your uploaded file!!Please upload again";
                return(Page());
            }
            else
            {
                var path   = Path.Combine(Directory.GetCurrentDirectory(), "Files", teamPresentation.FileName);
                var memory = new MemoryStream();
                using (var stream = new FileStream(path, FileMode.Open))
                {
                    await stream.CopyToAsync(memory);
                }
                memory.Position = 0;
                return(File(memory, GetContentType(path), Path.GetFileName(path)));
            }
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(RedirectToPage("AllTeams"));
            }

            string       username = HttpContext.Session.GetString("username");
            AppCondition app      = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1));

            if (username != app.AdminName)
            {
                return(RedirectToPage("AllTeams"));
            }

            Team = await _context.Team.FirstOrDefaultAsync(m => m.TeamId.Equals(id));

            if (Team == null)
            {
                return(RedirectToPage("AllTeams"));
            }

            int themeid = Team.ThemeID;

            allThemes = await _context.Theme.Where(t => t.EventID.Equals(app.EventID)).Select(
                a => new SelectListItem
            {
                Value = a.ThemeId.ToString(),
                Text  = a.ThemeName
            }
                ).ToListAsync();

            allUsers = await _context.User.ToListAsync();

            UserName = "******";

            allUsers = await _context.User.ToListAsync();

            IList <Member> allMembers = await _context.Member.Where(m => m.TeamID.Equals(Team.TeamId) && m.EventID.Equals(Team.EventID)).ToListAsync();

            totalMembers = allMembers.Count();

            TeamPresentation teamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamID.Equals(Team.TeamId));

            allEvents = await _context.Event.ToListAsync();

            if (teamPresentation == null)
            {
                hasPresentation = false;
            }
            else
            {
                hasPresentation = true;
            }

            return(Page());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            var teamid = Int32.Parse(Request.Form["teamid"]);

            TeamPresentation teamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamID.Equals(teamid));

            if (teamPresentation == null)
            {
                hasPresentation = false;
            }
            {
                hasPresentation = false;
            }

            Team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(teamid));

            if (Team == null)
            {
                return(RedirectToPage("Privacy"));
            }

            leader = await _context.User.FirstOrDefaultAsync(u => u.UserId.Equals(Team.UserID));

            allMembers = await _context.Member.Where(m => m.TeamID.Equals(Team.TeamId) && m.EventID.Equals(Team.EventID)).ToListAsync();

            eve = await _context.Event.FirstOrDefaultAsync(eve => eve.EventId.Equals(Team.EventID));

            EventCode = "Not-Found";
            EventName = "Not-Found";
            if (eve != null)
            {
                EventCode = eve.EventCode;
                EventName = eve.EventName;
            }

            if (teamPresentation == null)
            {
                Message = "There was an error with your uploaded file!!Please upload again";
                return(Page());
            }
            else
            {
                var path   = Path.Combine(Directory.GetCurrentDirectory(), "Files", teamPresentation.FileName);
                var memory = new MemoryStream();
                using (var stream = new FileStream(path, FileMode.Open))
                {
                    await stream.CopyToAsync(memory);
                }
                memory.Position = 0;
                return(File(memory, GetContentType(path), Path.GetFileName(path)));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1));

            int teamid = Team.TeamId;
            //To delete a team we need to remove all the member of that team
            IList <Member> teamMembers = await _context.Member.Where(m => m.TeamID.Equals(teamid) && m.EventID.Equals(app.EventID)).ToListAsync();

            foreach (var member in teamMembers)
            {
                _context.Member.Remove(member);
                await _context.SaveChangesAsync();
            }

            //Now that team has been deleted we have to remove votes for that team in the event
            IList <Vote> teamVotes = await _context.Vote.Where(v => v.TeamID.Equals(Team.TeamId) && v.EventID.Equals(app.EventID)).ToListAsync();

            foreach (var vote in teamVotes)
            {
                _context.Vote.Remove(vote);
                await _context.SaveChangesAsync();
            }

            //we also need to remove the presentation of the team if any
            TeamPresentation teamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamID.Equals(Team.TeamId));

            if (teamPresentation != null)
            {
                //We need to remove the file from the folder as well.
                string storedFile = teamPresentation.FileName;
                var    oldPath    = Path.Combine(Directory.GetCurrentDirectory(), "Files", storedFile);
                if (System.IO.File.Exists(oldPath))
                {
                    System.IO.File.Delete(oldPath);
                    _context.TeamPresentation.Remove(teamPresentation);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _context.TeamPresentation.Remove(teamPresentation);
                    await _context.SaveChangesAsync();
                }
            }

            _context.Team.Remove(Team);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Privacy"));
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TeamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(m => m.TeamPresentationId == id);

            if (TeamPresentation == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(RedirectToPage("AllTeams"));
            }

            string username = HttpContext.Session.GetString("username");

            if (username == null)
            {
                return(RedirectToPage("Privacy"));
            }

            Team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(id));

            if (Team == null)
            {
                return(RedirectToPage("AllTeams"));
            }

            leader = await _context.User.FirstOrDefaultAsync(u => u.UserId.Equals(Team.UserID));

            allMembers = await _context.Member.Where(m => m.TeamID.Equals(Team.TeamId) && m.EventID.Equals(Team.EventID)).ToListAsync();

            eve = await _context.Event.FirstOrDefaultAsync(eve => eve.EventId.Equals(Team.EventID));

            EventCode = "Not-Found";
            EventName = "Not-Found";
            if (eve != null)
            {
                EventCode = eve.EventCode;
                EventName = eve.EventName;
            }
            TeamPresentation teamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamID.Equals(Team.TeamId));

            if (teamPresentation != null)
            {
                hasPresentation = true;
            }
            else
            {
                hasPresentation = false;
            }

            return(Page());
        }
Beispiel #7
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TeamPresentation = await _context.TeamPresentation.FindAsync(id);

            if (TeamPresentation != null)
            {
                _context.TeamPresentation.Remove(TeamPresentation);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(RedirectToPage("AllUsers"));
            }

            User = await _context.User.FirstOrDefaultAsync(u => u.UserId.Equals(id));

            if (User == null)
            {
                return(RedirectToPage("AllUsers"));
            }

            //WE need to start removing the traces of the users throughout the application
            //1. Let begin by the votes
            allVotes = await _context.Vote.Where(v => v.UserID.Equals(User.UserId)).ToListAsync();

            foreach (var vote in allVotes)
            {
                _context.Vote.Remove(vote);
                await _context.SaveChangesAsync();
            }

            //2. Let remove his membership from various teams if he has any
            IList <Member> allMembersShips = await _context.Member.Where(m => m.UserID.Equals(User.UserId)).ToListAsync();

            foreach (var member in allMembersShips)
            {
                _context.Member.Remove(member);
                await _context.SaveChangesAsync();
            }

            //3. Judges position
            IList <Judge> AsJudge = await _context.Judge.Where(j => j.UserID.Equals(User.UserId)).ToListAsync();

            foreach (var judge in AsJudge)
            {
                _context.Judge.Remove(judge);
                await _context.SaveChangesAsync();
            }

            //4. All Team Leader postion
            IList <Team> allTeams = await _context.Team.Where(t => t.UserID.Equals(User.UserId)).ToListAsync();

            //The code inside the foreach loop is a refrence from the deleteTeamByAdmin Page
            foreach (var team in allTeams)
            {
                Team Team = await _context.Team.FindAsync(id);

                if (Team == null)
                {
                    return(RedirectToPage("Privacy"));
                }

                //Now that we are removing the team from the application database
                //we need to remove the traces of it as well otherwise they are likely to mess up with the
                //user experience and data management

                //1. We remove all the members of this team
                IList <Member> allMembers = await _context.Member.Where(m => m.TeamID.Equals(Team.TeamId)).ToListAsync();

                foreach (var mem in allMembers)
                {
                    _context.Member.Remove(mem);
                    await _context.SaveChangesAsync();
                }

                //2.We need to get rid of all the votes for this team
                IList <Vote> allVotes = await _context.Vote.Where(v => v.TeamID.Equals(Team.TeamId)).ToListAsync();

                foreach (var vote in allVotes)
                {
                    _context.Vote.Remove(vote);
                    await _context.SaveChangesAsync();
                }

                //3. We need to get rid of the presentation
                TeamPresentation teamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamID.Equals(Team.TeamId));

                if (teamPresentation != null)
                {
                    //Before we remove from the table
                    //We need to remove it from the Files folder

                    string storedFile = teamPresentation.FileName;
                    var    oldPath    = Path.Combine(Directory.GetCurrentDirectory(), "Files", storedFile);
                    if (System.IO.File.Exists(oldPath))
                    {
                        System.IO.File.Delete(oldPath);
                        _context.TeamPresentation.Remove(teamPresentation);
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        _context.TeamPresentation.Remove(teamPresentation);
                        await _context.SaveChangesAsync();
                    }
                }

                //Now we just remove the team as a final step

                _context.Team.Remove(Team);
                await _context.SaveChangesAsync();
            }

            //Now in the end we are just gonna remove the users

            _context.User.Remove(User);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./AllUsers"));
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(RedirectToPage("AllTeams"));
            }

            string       username = HttpContext.Session.GetString("username");
            AppCondition app      = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1));

            //We need to make sure that the team exists
            Team = await _context.Team.FirstOrDefaultAsync(t => t.TeamId.Equals(id));

            if (Team == null)
            {
                return(RedirectToPage("AllTeams"));
            }

            allEvents = await _context.Event.ToListAsync();

            allUsers = await _context.User.ToListAsync();

            Leader    = "Not-Found";
            FullName  = "Not-Found";
            EventCode = "Not-Found";

            foreach (var user in allUsers)
            {
                if (Team.UserID.Equals(user.UserId))
                {
                    Leader   = user.UserName;
                    FullName = user.FullName;
                    break;
                }
            }

            foreach (var eve in allEvents)
            {
                if (Team.EventID.Equals(eve.EventId))
                {
                    EventCode = eve.EventCode;
                    break;
                }
            }

            IList <Member> allMembers = await _context.Member.Where(m => m.TeamID.Equals(Team.TeamId) && m.EventID.Equals(Team.EventID)).ToListAsync();

            //We need to add plus 1 as for admin the leader is also a members
            totalMembers = allMembers.Count() + 1;

            IList <Vote> teamVotes = await _context.Vote.Where(v => v.TeamID.Equals(Team.TeamId)).ToListAsync();

            totalVotes = teamVotes.Count();

            TeamPresentation teamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamID.Equals(Team.TeamId));

            if (teamPresentation != null)
            {
                hasPresentation = true;
                FileName        = teamPresentation.FileName;
            }
            else
            {
                hasPresentation = false;
                FileName        = "None";
            }


            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Team = await _context.Team.FindAsync(id);

            if (Team == null)
            {
                return(RedirectToPage("Privacy"));
            }

            //Now that we are removing the team from the application database
            //we need to remove the traces of it as well otherwise they are likely to mess up with the
            //user experience and data management

            //1. We remove all the members of this team
            IList <Member> allMembers = await _context.Member.Where(m => m.TeamID.Equals(Team.TeamId)).ToListAsync();

            foreach (var mem in allMembers)
            {
                _context.Member.Remove(mem);
                await _context.SaveChangesAsync();
            }

            //2.We need to get rid of all the votes for this team
            IList <Vote> allVotes = await _context.Vote.Where(v => v.TeamID.Equals(Team.TeamId)).ToListAsync();

            foreach (var vote in allVotes)
            {
                _context.Vote.Remove(vote);
                await _context.SaveChangesAsync();
            }

            //3. We need to get rid of the presentation
            TeamPresentation teamPresentation = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamID.Equals(Team.TeamId));

            if (teamPresentation != null)
            {
                //Before we remove from the table
                //We need to remove it from the Files folder

                string storedFile = teamPresentation.FileName;
                var    oldPath    = Path.Combine(Directory.GetCurrentDirectory(), "Files", storedFile);
                if (System.IO.File.Exists(oldPath))
                {
                    System.IO.File.Delete(oldPath);
                    _context.TeamPresentation.Remove(teamPresentation);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _context.TeamPresentation.Remove(teamPresentation);
                    await _context.SaveChangesAsync();
                }
            }

            //Now we just remove the team as a final step

            _context.Team.Remove(Team);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./AllTeams"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            string username = HttpContext.Session.GetString("username");
            User   user     = await _context.User.FirstOrDefaultAsync(u => u.UserName.Equals(username));

            AppCondition app = await _context.AppCondition.FirstOrDefaultAsync(app => app.AppConditionId.Equals(1));

            Team = await _context.Team.FirstOrDefaultAsync(t => t.UserID.Equals(user.UserId) && t.EventID.Equals(app.EventID));

            //The team won't be null because of test performed earlier
            if ((UploadFile == null) || (UploadFile.Length == 0))
            {
                Message = "Please select a file first to upload!!";
                return(Page());
            }

            //Before we store the file we need to get rid of the previous file if any
            TeamPresentation teamPresentation1 = await _context.TeamPresentation.FirstOrDefaultAsync(tp => tp.TeamID.Equals(Team.TeamId) && tp.EventID.Equals(app.EventID));

            if (teamPresentation1 != null)
            {
                //That means team leader has already upload a file before this
                //So we need to start by deleting that file first
                string storedFile = teamPresentation1.FileName;
                var    oldPath    = Path.Combine(Directory.GetCurrentDirectory(), "Files", storedFile);
                if (System.IO.File.Exists(oldPath))
                {
                    System.IO.File.Delete(oldPath);
                    _context.TeamPresentation.Remove(teamPresentation1);
                    await _context.SaveChangesAsync();

                    Message = "Your previous file has been deleted!!";
                }
                else
                {
                }
            }

            string extension = Path.GetExtension(UploadFile.FileName);
            //Since team name is unique for an event and username is unique always
            string fileName = Team.JoinCode + username + Team.TeamId + extension;

            var path = Path.Combine(
                Directory.GetCurrentDirectory(), "Files", fileName);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await UploadFile.CopyToAsync(stream);
            }

            Message = "You file has been uploaded!!";

            TeamPresentation teamPresentation = new TeamPresentation()
            {
                TeamID   = Team.TeamId,
                EventID  = Team.EventID,
                FileName = fileName,
                TeamName = Team.TeamName,
            };

            _context.TeamPresentation.Add(teamPresentation);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./MyTeam"));
        }