Example #1
0
        public CouncilDecision GetCouncilDecision()
        {
            GaptDbContext db  = new GaptDbContext();
            var           ipc = db.InPrincipal_Council.SingleOrDefault(m => m.InPrincipalId == InPrincipalId);

            return(ipc.CouncilDecision);
        }
Example #2
0
        public General GetGeneral()
        {
            GaptDbContext db      = new GaptDbContext();
            var           general = db.Generals.SingleOrDefault(t => t.Id == GeneralId);

            return(general);
        }
Example #3
0
        public PvcApproval GetPvcApproval()
        {
            GaptDbContext db  = new GaptDbContext();
            var           ipp = db.InPrincipal_Pvc.SingleOrDefault(m => m.InPrincipalId == InPrincipalId);

            return(ipp.PvcApproval);
        }
Example #4
0
        public Proposal GetProposal()
        {
            GaptDbContext db       = new GaptDbContext();
            var           proposal = db.Proposals.SingleOrDefault(t => t.GeneralId == Id);

            return(proposal);
        }
Example #5
0
        public Year GetYear()
        {
            GaptDbContext db   = new GaptDbContext();
            var           year = db.Years.SingleOrDefault(m => m.Id == YearId);

            return(year);
        }
Example #6
0
        public bool IsEditable(string userId)
        {
            ApplicationDbContext adb = new ApplicationDbContext();
            GaptDbContext        db  = new GaptDbContext();

            if (IsInEdit == true)
            {
                if (UserEditing == userId)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (userId == CreatedBy)
            {
                return(true);
            }

            var pg = db.Proposer_General.SingleOrDefault(m => m.UserId == userId && m.GeneralId == GeneralId);

            if (pg != null)
            {
                return(true);
            }

            var sg = db.Shared_General.SingleOrDefault(m => m.UserId == userId && m.GeneralId == GeneralId);

            if (sg != null)
            {
                return(true);
            }

            var query     = "Select Distinct r.Name From dbo.AspNetRoles r, dbo.AspNetUserRoles ur Where r.Id = ur.RoleId and ur.UserId = '" + userId + "'";
            var roleNames = adb.Database.SqlQuery <string>(query).ToList();

            //if (roleNames.Contains(RoleName.Lecturer))
            //{
            //    var pg = db.Proposer_General.SingleOrDefault(m => m.GeneralId == GeneralId && m.UserId == userId);
            //    if (pg != null)
            //    {
            //        return true;
            //    }
            //    else
            //    {
            //        return false;
            //    }
            //}
            if (roleNames.Contains(RoleName.Apqru))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #7
0
        public int GetReplyCount()
        {
            GaptDbContext db      = new GaptDbContext();
            var           replies = db.Comments.Where(m => m.ReplyTo == Id).ToList();

            return(replies.Count());
        }
Example #8
0
        public Ref_Unit GetUnit()
        {
            GaptDbContext db   = new GaptDbContext();
            var           unit = db.Ref_Unit.SingleOrDefault(m => m.Id == UnitId);

            return(unit);
        }
Example #9
0
        public ProgrammeRationale GetProgrammeRationale()
        {
            GaptDbContext db = new GaptDbContext();
            var           pr = db.ProgrammeRationales.SingleOrDefault(t => t.Id == ProgrammeRationaleId);

            return(pr);
        }
Example #10
0
        public SenateDecision GetSenateDecision()
        {
            GaptDbContext db  = new GaptDbContext();
            var           ips = db.InPrincipal_Senate.SingleOrDefault(m => m.InPrincipalId == InPrincipalId);

            return(ips.SenateDecision);
        }
Example #11
0
        public List <int> GetServDeptsIds()
        {
            GaptDbContext db  = new GaptDbContext();
            var           ids = db.Database.SqlQuery <int>("Select DepartmentId From dbo.Department_General Where GeneralId = " + Id + " and Type = 3").ToList();

            if (ids == null)
            {
                return(null);
            }
            return(ids);
        }
Example #12
0
        public string GetLevelName()
        {
            GaptDbContext db = new GaptDbContext();

            if (LevelId == null)
            {
                return(null);
            }
            var level = db.Ref_Level.SingleOrDefault(t => t.Id == LevelId);

            return(level.Name);
        }
Example #13
0
        public string GetDeliveryName()
        {
            GaptDbContext db = new GaptDbContext();

            if (DeliveryId == null)
            {
                return(null);
            }
            var mode = db.Ref_Delivery.SingleOrDefault(t => t.Id == DeliveryId);

            return(mode.Name);
        }
Example #14
0
        public string GetFacultyName()
        {
            GaptDbContext db = new GaptDbContext();

            if (FacultyId == null)
            {
                return(null);
            }
            var faculty = db.Ref_Faculty.SingleOrDefault(t => t.Id == FacultyId);

            return(faculty.Name);
        }
Example #15
0
        public List <Comment> GetComments()
        {
            GaptDbContext  db       = new GaptDbContext();
            var            tcs      = db.Thread_Comment.Where(m => m.ThreadId == ThreadId).ToList();
            List <Comment> comments = new List <Comment>();

            foreach (Thread_Comment tc in tcs)
            {
                var comment = db.Comments.SingleOrDefault(m => m.Id == tc.CommentId);
                comments.Add(comment);
            }
            return(comments);
        }
Example #16
0
        public List <StatementIE> GetStatements()
        {
            GaptDbContext      db            = new GaptDbContext();
            var                statementsIds = db.Database.SqlQuery <int>("Select StatementId From dbo.IncomeExpenditure_StatementIE Where IncomeExpenditureId = " + Id).ToList();
            List <StatementIE> statements    = new List <StatementIE>();

            foreach (int id in statementsIds)
            {
                var statement = db.StatementIEs.SingleOrDefault(m => m.Id == id);
                statements.Add(statement);
            }
            return(statements);
        }
Example #17
0
        private bool LecturerCanView(string userId)
        {
            // return true if lecturer is one of the proposers
            GaptDbContext db = new GaptDbContext();
            var           pg = db.Proposer_General.SingleOrDefault(m => m.GeneralId == GeneralId && m.UserId == userId);

            if (pg != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #18
0
        public List <Reviewer> GetReviewers()
        {
            GaptDbContext   db          = new GaptDbContext();
            var             reviewerIds = db.Database.SqlQuery <int>("Select ReviewerId From dbo.ExternalReview_Reviewer Where ExternalReviewId = " + Id).ToList();
            List <Reviewer> reviewers   = new List <Reviewer>();

            foreach (int id in reviewerIds)
            {
                var reviewer = db.Reviewers.SingleOrDefault(m => m.Id == id);
                reviewers.Add(reviewer);
            }
            var sorted = reviewers.OrderBy(m => m.Name).ToList();

            return(sorted);
        }
Example #19
0
        //returns true if ALL faculties departments accepted
        public bool HasFacultyApproval()
        {
            if (ApprovalId == null)
            {
                return(false);
            }

            GaptDbContext db      = new GaptDbContext();
            var           general = db.Generals.SingleOrDefault(t => t.Id == GeneralId);

            var faculty = general.Ref_Faculty;

            if (faculty == null)
            {
                return(false);
            }
            var recommendation = faculty.GetRecommendation(Id);

            if (recommendation.Selection == false || recommendation.Selection == null)
            {
                return(false);
            }

            var collabDepts = general.GetCollabDepts();

            foreach (Ref_Department dept in collabDepts)
            {
                var endorsement = dept.GetCollabEndorsement(Id);
                if (endorsement.Selection == false || endorsement.Selection == null)
                {
                    return(false);
                }
            }

            var servDepts = general.GetServDepts();

            foreach (Ref_Department dept in servDepts)
            {
                var statement = dept.GetServStatement(Id);
                if (statement.Selection == false || statement.Selection == null)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #20
0
        public List <Ref_Type> GetTypes()
        {
            GaptDbContext db  = new GaptDbContext();
            var           ids = db.Database.SqlQuery <int>("Select TypeId From dbo.Type_General Where GeneralId = " + Id).ToList();

            if (ids == null)
            {
                return(null);
            }
            var types = new List <Ref_Type>();

            foreach (int id in ids)
            {
                var type = db.Ref_Type.SingleOrDefault(m => m.Id == id);
                types.Add(type);
            }
            return(types);
        }
Example #21
0
        public List <Ref_Department> GetServDepts()
        {
            GaptDbContext db  = new GaptDbContext();
            var           ids = db.Database.SqlQuery <int>("Select DepartmentId From dbo.Department_General Where GeneralId = " + Id + " and Type = 3").ToList();

            if (ids == null)
            {
                return(null);
            }
            var depts = new List <Ref_Department>();

            foreach (int id in ids)
            {
                var dept = db.Ref_Department.SingleOrDefault(m => m.Id == id);
                depts.Add(dept);
            }
            return(depts);
        }
Example #22
0
        public List <ApplicationUser> GetShared()
        {
            GaptDbContext        db  = new GaptDbContext();
            ApplicationDbContext adb = new ApplicationDbContext();
            var ids = db.Database.SqlQuery <string>("Select UserId From dbo.Shared_General Where GeneralId = '" + Id + "'").ToList();

            if (ids == null)
            {
                return(null);
            }
            var users = new List <ApplicationUser>();

            foreach (string id in ids)
            {
                var user = adb.Database.SqlQuery <ApplicationUser>("Select * from AspNetUsers Where Id = '" + id + "'").First();
                users.Add(user);
            }
            return(users);
        }
Example #23
0
        //returns true if one of  pvc/senate/council rejected
        public bool HasInPrincipleRejection()
        {
            if (InPrincipalId == null)
            {
                return(false);
            }

            GaptDbContext db      = new GaptDbContext();
            var           general = db.Generals.SingleOrDefault(t => t.Id == GeneralId);
            var           pvc     = GetPvcApproval();
            var           senate  = GetSenateDecision();
            var           council = GetCouncilDecision();

            if (pvc != null)
            {
                if (pvc.Selection == false)
                {
                    return(true);
                }
            }

            if (senate != null)
            {
                if (senate.Selection == false && senate.SignedBy != null)
                {
                    return(true);
                }
            }

            if (council != null)
            {
                if (council.Selection == false && council.SignedBy != null)
                {
                    return(true);
                }
            }


            return(false);
        }
Example #24
0
        public string GetErrorMessage()
        {
            GaptDbContext db            = new GaptDbContext();
            var           year          = GetYear();
            var           tentativePsId = year.TentativePsId;
            var           pr            = db.ProgrammeRationales.SingleOrDefault(m => m.TentativePsId == tentativePsId);
            var           proposal      = db.Proposals.SingleOrDefault(m => m.ProgrammeRationaleId == pr.Id);
            string        s             = null;

            if (Ects == null || Ects < 1)
            {
                s = "Section B Tentative Programme of Study : Year " + GetYear().YearNo + " Unit " + GetUnit().Code + " ECTs";
            }

            else if (Compensating == 0 && proposal.GetGeneral().LevelId == 1)
            {
                if (String.IsNullOrWhiteSpace(CompensatingReason))
                {
                    s = "Section B Tentative Programme of Study : Year " + GetYear().YearNo + " Unit " + GetUnit().Code + " NC Reason";
                }
            }
            return(s);
        }
Example #25
0
        public RecommendationFic GetRecommendation(int pid)
        {
            GaptDbContext db       = new GaptDbContext();
            var           proposal = db.Proposals.SingleOrDefault(t => t.Id == pid);

            var ars = db.Approval_Recommendation.Where(m => m.ApprovalId == proposal.ApprovalId).ToList();

            if (ars == null)
            {
                return(null);
            }
            else
            {
                foreach (Approval_Recommendation ar in ars)
                {
                    var recommendation = db.RecommendationFics.SingleOrDefault(m => m.Id == ar.RecommendationId && m.FacultyId == Id);
                    if (recommendation != null)
                    {
                        return(recommendation);
                    }
                }
                return(null);
            }
        }
Example #26
0
        public EndorsementCollab GetCollabEndorsement(int pid)
        {
            GaptDbContext db       = new GaptDbContext();
            var           proposal = db.Proposals.SingleOrDefault(t => t.Id == pid);

            var aes = db.Approval_Endorsement.Where(m => m.ApprovalId == proposal.ApprovalId).ToList();

            if (aes == null)
            {
                return(null);
            }
            else
            {
                foreach (Approval_Endorsement ae in aes)
                {
                    var endCollab = db.EndorsementCollabs.SingleOrDefault(m => m.Id == ae.EndorsementId && m.DepartmentId == Id);
                    if (endCollab != null)
                    {
                        return(endCollab);
                    }
                }
                return(null);
            }
        }
Example #27
0
        public StatementServ GetServStatement(int pid)
        {
            GaptDbContext db       = new GaptDbContext();
            var           proposal = db.Proposals.SingleOrDefault(t => t.Id == pid);

            var apps = db.Approval_Statement.Where(m => m.ApprovalId == proposal.ApprovalId).ToList();

            if (apps == null)
            {
                return(null);
            }
            else
            {
                foreach (Approval_Statement app in apps)
                {
                    var stmServ = db.StatementServs.SingleOrDefault(m => m.Id == app.StatementId && m.DepartmentId == Id);
                    if (stmServ != null)
                    {
                        return(stmServ);
                    }
                }
                return(null);
            }
        }
Example #28
0
        public List <Year_Unit> GetYearUnits()
        {
            var db = new GaptDbContext();

            return(db.Year_Unit.Where(m => m.YearId == Id).ToList());
        }
Example #29
0
        public List <Year> GetYears()
        {
            var db = new GaptDbContext();

            return(db.Years.Where(m => m.TentativePsId == Id).OrderBy(m => m.YearNo).ToList());
        }
Example #30
0
        public bool IsViewable(string userId, string email = null)
        {
            ApplicationDbContext adb = new ApplicationDbContext();
            GaptDbContext        db  = new GaptDbContext();

            if (userId == CreatedBy)
            {
                return(true);
            }

            var pg = db.Proposer_General.SingleOrDefault(m => m.UserId == userId && m.GeneralId == GeneralId);

            if (pg != null)
            {
                return(true);
            }

            var sg = db.Shared_General.SingleOrDefault(m => m.UserId == userId && m.GeneralId == GeneralId);

            if (sg != null)
            {
                return(true);
            }

            var query     = "Select Distinct r.Name From dbo.AspNetRoles r, dbo.AspNetUserRoles ur Where r.Id = ur.RoleId and ur.UserId = '" + userId + "'";
            var roleNames = adb.Database.SqlQuery <string>(query).ToList();

            if (roleNames.Contains(RoleName.Lecturer) && roleNames.Contains(RoleName.Dean) && roleNames.Contains(RoleName.HoD))
            {
                // if user is in these 3 roles, give permission where appropriate

                // give lecturer permission
                if (LecturerCanView(userId))
                {
                    return(true);
                }

                //give dean permission
                if (DeanCanView(userId))
                {
                    return(true);
                }

                // give hod permission
                if (HodCanView(userId))
                {
                    return(true);
                }

                //deny permission
                return(false);
            }
            else if (roleNames.Contains(RoleName.Lecturer) && roleNames.Contains(RoleName.Dean))
            {
                // give lecturer permission
                if (LecturerCanView(userId))
                {
                    return(true);
                }

                //give dean permission
                if (DeanCanView(userId))
                {
                    return(true);
                }
                return(false);
            }
            else if (roleNames.Contains(RoleName.Lecturer) && roleNames.Contains(RoleName.HoD))
            {
                // give lecturer permission
                if (LecturerCanView(userId))
                {
                    return(true);
                }

                // give hod permission
                if (HodCanView(userId))
                {
                    return(true);
                }
                return(false);
            }
            else if (roleNames.Contains(RoleName.Dean) && roleNames.Contains(RoleName.HoD))
            {
                //give dean permission
                if (DeanCanView(userId))
                {
                    return(true);
                }

                // give hod permission
                if (HodCanView(userId))
                {
                    return(true);
                }
                return(false);
            }
            else if (roleNames.Contains(RoleName.Lecturer))
            {
                return(LecturerCanView(userId));
            }
            else if (roleNames.Contains(RoleName.Dean))
            {
                return(DeanCanView(userId));
            }
            else if (roleNames.Contains(RoleName.HoD))
            {
                return(HodCanView(userId));
            }
            else if (roleNames.Contains(RoleName.ER))
            {
                if (ExternalReviewId == null)
                {
                    return(false);
                }
                // only give permission to external reviewers linked to the proposal
                var er        = db.ExternalReviews.SingleOrDefault(m => m.Id == ExternalReviewId);
                var reviewers = er.GetReviewers();
                foreach (Reviewer reviewer in reviewers)
                {
                    if (reviewer.Email == email)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }