Example #1
0
        /// <summary>
        /// Set the permissions for the instructor to be able to view the student's logbook.
        /// </summary>
        /// <param name="instructorstudent"></param>
        public void SetCFIPermissions(InstructorStudent instructorstudent)
        {
            if (String.IsNullOrEmpty(this.User))
            {
                throw new MyFlightbookException("No username for CFIStudentmap");
            }

            DBHelper dbh = new DBHelper("UPDATE students SET CanViewStudent=?canView WHERE StudentName=?user AND CFIName=?instructor");

            dbh.DoNonQuery((comm) =>
            {
                // Sanity check - can't add to logbook if you can't view it.
                if (!instructorstudent.CanViewLogbook)
                {
                    instructorstudent.CanAddLogbook = false;
                }

                uint perms = ((uint)(instructorstudent.CanViewLogbook ? InstructorStudent.PermissionMask.ViewLogbook : 0) | (uint)(instructorstudent.CanAddLogbook ? InstructorStudent.PermissionMask.AddLogbook : 0));
                comm.Parameters.AddWithValue("canView", perms);
                comm.Parameters.AddWithValue("user", this.User);
                comm.Parameters.AddWithValue("instructor", instructorstudent.UserName);
            });
            // refresh
            LoadInstructors();
        }
        protected string GetUserName(out string szError)
        {
            szError = string.Empty;
            string szUser    = Page.User.Identity.Name; // default value
            string szStudent = util.GetStringParam(Request, "u");

            if (!String.IsNullOrEmpty(szStudent))
            {
                // See if the current user is authorized to view print view of the specified user
                CFIStudentMap     sm      = new CFIStudentMap(Page.User.Identity.Name);
                InstructorStudent student = CFIStudentMap.GetInstructorStudent(sm.Students, szStudent);
                if (student == null)
                {
                    szError = Resources.SignOff.ViewStudentNoSuchStudent;
                }
                else if (!student.CanViewLogbook)
                {
                    szError = Resources.SignOff.ViewStudentLogbookUnauthorized;
                }
                else
                {
                    szUser = szStudent;     // all good - can view.
                }
            }
            return(szUser);
        }
        public ActionResult AssignCourse(int StudentId, int instructorID)
        {
            #region Logic Here

            /*  Get the instuctorId, StudentId, CourseId
             *  assign the instuctorId, StudentId in instructorstudent entity
             *  assign the StudentId, CourseId in studentcourse entity
             */
            #endregion

            int courseId = Convert.ToInt32(TempData["courseId"]);

            StudentCourse studentCourse = new StudentCourse
            {
                Fk_CourseId  = courseId,
                Fk_StudentId = StudentId
            };
            ctx.StudentCourses.Add(studentCourse);

            InstructorStudent instructorStudent = new InstructorStudent
            {
                Fk_InstructorId = instructorID,
                Fk_StudentId    = StudentId
            };
            ctx.InstructorStudents.Add(instructorStudent);

            ctx.SaveChanges();
            return(RedirectToAction("Index"));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        Master.SelectedTab = tabID.tabTraining;

        if (!IsPostBack)
        {
            hdnStudent.Value = Page.User.Identity.Name; //default
            string            szStudent = util.GetStringParam(Request, "student");
            CFIStudentMap     sm        = new CFIStudentMap(Page.User.Identity.Name);
            InstructorStudent student   = CFIStudentMap.GetInstructorStudent(sm.Students, szStudent);
            if (student == null)
            {
                lblErr.Text = Resources.SignOff.ViewStudentNoSuchStudent;
            }
            else
            {
                if (!student.CanViewLogbook)
                {
                    lblErr.Text = Master.Title = Resources.SignOff.ViewStudentLogbookUnauthorized;
                }
                else
                {
                    // If we're here, we are authorized
                    lblHeader.Text   = String.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.SignOff.ViewStudentLogbookHeader, student.UserFullName);
                    hdnStudent.Value = student.UserName;
                    Restriction      = new FlightQuery(student.UserName);

                    if (mfbLogbook1.CanResignValidFlights = student.CanAddLogbook)
                    {
                        mfbEditFlight.FlightUser = student.UserName;
                        mfbEditFlight.SetUpNewOrEdit(LogbookEntry.idFlightNew);
                    }
                    else
                    {
                        apcNewFlight.Visible = false;
                    }

                    if (!String.IsNullOrEmpty(hdnStudent.Value))
                    {
                        UpdateForUser(hdnStudent.Value);
                    }

                    mfbSearchForm.Username = printOptions.UserName = student.UserName;
                    ResolvePrintLink();
                }
            }

            pnlLogbook.Visible = (lblErr.Text.Length == 0);
        }

        if (pnlLogbook.Visible && mfbChartTotals.Visible)
        {
            mfbChartTotals.HistogramManager = LogbookEntryDisplay.GetHistogramManager(mfbLogbook1.Data, hdnStudent.Value);   // do this every time, since charttotals doesn't persist its data.
        }
    }
    private LogbookEntryDisplay LoadFlight(int idFlight)
    {
        // Check to see if the requested flight belongs to the current user, or if they're authorized.
        // It's an extra database hit (or more, if viewing a student flight), but will let us figure out next/previous
        string szFlightOwner = LogbookEntry.OwnerForFlight(idFlight);

        if (String.IsNullOrEmpty(szFlightOwner))
        {
            throw new MyFlightbookException(Resources.LogbookEntry.errNoSuchFlight);
        }

        bool fIsAdmin = (util.GetIntParam(Request, "a", 0) != 0 && MyFlightbook.Profile.GetUser(Page.User.Identity.Name).CanSupport);

        // Check that you own the flight, or are admin.  If not either of these, check to see if you are authorized
        if (String.Compare(szFlightOwner, Page.User.Identity.Name, StringComparison.OrdinalIgnoreCase) != 0 && !fIsAdmin)
        {
            // check for authorized by student
            CFIStudentMap     sm      = new CFIStudentMap(Page.User.Identity.Name);
            InstructorStudent student = sm.GetInstructorStudent(sm.Students, szFlightOwner);
            if (student == null || !student.CanViewLogbook)
            {
                throw new MyFlightbookException(Resources.SignOff.ViewStudentLogbookUnauthorized);
            }

            // At this point, we're viewing a student's flight.  Change the return link.
            mvReturn.SetActiveView(vwReturnStudent);
            lnkReturnStudent.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "~/Member/StudentLogbook.aspx?student={0}", szFlightOwner);
            lnkReturnStudent.Text        = String.Format(CultureInfo.CurrentCulture, Resources.Profile.ReturnToStudent, MyFlightbook.Profile.GetUser(szFlightOwner).UserFullName);
            popmenu.Visible = false;
        }

        // If we're here, we're authorized
        LogbookEntryDisplay led = new LogbookEntryDisplay(idFlight, szFlightOwner, LogbookEntry.LoadTelemetryOption.LoadAll);

        if (!led.HasFlightData)
        {
            led.FlightData = string.Empty;
        }

        if (String.IsNullOrEmpty(led.FlightData))
        {
            apcChart.Visible = apcDownload.Visible = apcRaw.Visible = false;
        }

        lblFlightDate.Text     = led.Date.ToShortDateString();
        lblFlightAircraft.Text = led.TailNumDisplay ?? string.Empty;
        lblCatClass.Text       = String.Format(CultureInfo.CurrentCulture, "({0})", led.CatClassDisplay);
        lblCatClass.CssClass   = led.IsOverridden ? "ExceptionData" : string.Empty;
        litDesc.Text           = led.CommentWithReplacedApproaches;
        lblRoute.Text          = led.Route.ToUpper(CultureInfo.CurrentCulture);

        Page.Title = String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.FlightDetailsTitle, led.Date);

        return(led);
    }
Example #6
0
    protected void ckCanAddLogbook_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox    ck   = (CheckBox)sender;
        GridViewRow gvr  = (GridViewRow)ck.NamingContainer;
        int         iRow = gvr.RowIndex;

        if (iRow >= 0 && iRow < m_sm.Instructors.Count())
        {
            InstructorStudent instructorStudent = m_sm.Instructors.ElementAt(iRow);
            instructorStudent.CanAddLogbook = ck.Checked;
            m_sm.SetCFIPermissions(instructorStudent);
        }
        gvInstructors.DataSource = m_sm.Instructors;
        gvInstructors.DataBind();
    }
    /// <summary>
    /// Loads the specified flight into m_le, cached to avoid excess DB thrashing.
    /// </summary>
    /// <param name="idFlight">ID of the flight to load</param>
    protected void LoadLogbookEntry(int idFlight)
    {
        string szCacheKey = KeyCacheFlight(idFlight);

        Title = (string)GetLocalResourceObject("PageResource1.Title");

        m_le = null;
        if (!IsPostBack || Session[szCacheKey] == null)
        {
            m_le = new LogbookEntry();

            bool fIsAdmin = (util.GetIntParam(Request, "a", 0) != 0 && MyFlightbook.Profile.GetUser(Page.User.Identity.Name).CanSupport);
            if (m_le.FLoadFromDB(idFlight, User.Identity.Name, LogbookEntry.LoadTelemetryOption.LoadAll, true))
            {
                if (!m_le.HasFlightData)
                {
                    throw new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, Resources.FlightData.errNoDataForFlight, idFlight));
                }

                // check to see if you own the flight.  You own it if:
                // a) Admin
                // b) username=Page identity, or
                // c) authorized by student.
                if (!fIsAdmin && String.Compare(m_le.User, User.Identity.Name, StringComparison.Ordinal) != 0)
                {
                    // check for authorized by student
                    CFIStudentMap     sm      = new CFIStudentMap(Page.User.Identity.Name);
                    InstructorStudent student = sm.GetInstructorStudent(sm.Students, m_le.User);
                    if (student == null || !student.CanViewLogbook)
                    {
                        throw new MyFlightbookException(Resources.SignOff.ViewStudentLogbookUnauthorized);
                    }
                }

                Session[szCacheKey] = m_le;
            }
            else
            {
                throw new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, Resources.FlightData.errCantLoadFlight, idFlight.ToString(CultureInfo.InvariantCulture), m_le.ErrorString));
            }
        }
        else
        {
            m_le = (LogbookEntry)Session[szCacheKey];
        }
    }
Example #8
0
        /// <summary>
        /// Set the permissions for the instructor to be able to view the student's logbook.
        /// </summary>
        /// <param name="instructorstudent"></param>
        public void SetCFIPermissions(InstructorStudent instructorstudent)
        {
            if (String.IsNullOrEmpty(this.User))
            {
                throw new MyFlightbookException("No username for CFIStudentmap");
            }

            DBHelper dbh = new DBHelper("UPDATE students SET CanViewStudent=?canView WHERE StudentName=?user AND CFIName=?instructor");

            dbh.DoNonQuery((comm) =>
            {
                comm.Parameters.AddWithValue("canView", instructorstudent.CanViewLogbook);
                comm.Parameters.AddWithValue("user", this.User);
                comm.Parameters.AddWithValue("instructor", instructorstudent.UserName);
            });
            // refresh
            LoadInstructors();
        }
Example #9
0
    /// <summary>
    /// Checks to see if the viewer is an instructor of the owner of the flight; throws an exception if not.
    /// </summary>
    /// <param name="szFlightOwner">The owner of the flight</param>
    protected static void CheckCanViewFlight(string szFlightOwner, string szViewer)
    {
        if (szFlightOwner == null)
        {
            throw new ArgumentNullException(nameof(szFlightOwner));
        }
        if (szViewer == null)
        {
            throw new ArgumentNullException(nameof(szViewer));
        }

        MyFlightbook.Instruction.CFIStudentMap sm = new MyFlightbook.Instruction.CFIStudentMap(szViewer);
        InstructorStudent student = MyFlightbook.Instruction.CFIStudentMap.GetInstructorStudent(sm.Students, szFlightOwner);

        if (student == null || !student.CanViewLogbook)
        {
            throw new MyFlightbookException(Resources.SignOff.ViewStudentLogbookUnauthorized);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Master.SelectedTab = tabID.tabTraining;
        Master.Layout      = MasterPage.LayoutMode.Accordion;

        if (!IsPostBack)
        {
            string            szStudent = util.GetStringParam(Request, "student");
            CFIStudentMap     sm        = new CFIStudentMap(Page.User.Identity.Name);
            InstructorStudent student   = sm.GetInstructorStudent(sm.Students, szStudent);
            if (student == null)
            {
                lblErr.Text = Resources.SignOff.ViewStudentNoSuchStudent;
            }
            else
            {
                if (!student.CanViewLogbook)
                {
                    lblErr.Text = Master.Title = Resources.SignOff.ViewStudentLogbookUnauthorized;
                }
                else
                {
                    // If we're here, we are authorized
                    lblHeader.Text   = String.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.SignOff.ViewStudentLogbookHeader, student.UserFullName);
                    hdnStudent.Value = student.UserName;
                    Restriction      = new FlightQuery(student.UserName);

                    if (!String.IsNullOrEmpty(hdnStudent.Value))
                    {
                        UpdateForUser(hdnStudent.Value);
                    }
                }
            }

            pnlLogbook.Visible = (lblErr.Text.Length == 0);
        }

        if (pnlLogbook.Visible && mfbChartTotals.Visible)
        {
            mfbChartTotals.SourceData = mfbLogbook1.Data;   // do this every time, since charttotals doesn't persist its data.
        }
    }
    protected void ckCanViewLogbook_CheckedChanged(object sender, EventArgs e)
    {
        if (sender == null)
        {
            throw new ArgumentNullException(nameof(sender));
        }

        CheckBox    ck   = (CheckBox)sender;
        GridViewRow gvr  = (GridViewRow)ck.NamingContainer;
        int         iRow = gvr.RowIndex;

        if (iRow >= 0 && iRow < m_sm.Instructors.Count())
        {
            InstructorStudent instructorStudent = m_sm.Instructors.ElementAt(iRow);
            instructorStudent.CanViewLogbook = ck.Checked;
            if (!ck.Checked)
            {
                instructorStudent.CanAddLogbook = false;
            }
            m_sm.SetCFIPermissions(instructorStudent);
        }
        gvInstructors.DataSource = m_sm.Instructors;
        gvInstructors.DataBind();
    }
Example #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Master.SelectedTab = tabID.tabTraining;
            Title = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.TitleProfile, Branding.CurrentBrand.AppName);

            pnlError.Visible = false;

            if (!IsPostBack)
            {
                try
                {
                    if (Request.PathInfo.Length > 0)
                    {
                        m_szTargetUser = Request.PathInfo.Substring(1);
                    }

                    bool fMemberEndorsement = util.GetIntParam(Request, "extern", 0) == 0;

                    if (m_szTargetUser.Length == 0 && fMemberEndorsement)
                    {
                        pnlEndorsement.Visible = false; // hide the new endorsement panel - just show all endorsements given
                    }
                    else
                    {
                        mfbEditEndorsement1.StudentType = fMemberEndorsement ? Endorsement.StudentTypes.Member : Endorsement.StudentTypes.External;

                        if (fMemberEndorsement)
                        {
                            CFIStudentMap sm = new CFIStudentMap(Page.User.Identity.Name);
                            if (!sm.IsInstructorOf(m_szTargetUser))
                            {
                                throw new MyFlightbookValidationException(Resources.Profile.errNotAuthorizedToEndorse);
                            }
                            InstructorStudent student = CFIStudentMap.GetInstructorStudent(sm.Students, m_szTargetUser);
                            if (student.CanViewLogbook)
                            {
                                pnlNonOwnedEndorsements.Visible           = true;
                                mfbNonOwnedEndorsements.Student           = m_szTargetUser;
                                mfbNonOwnedEndorsements.ExcludeInstructor = Page.User.Identity.Name;
                                mfbNonOwnedEndorsements.RefreshEndorsements();

                                mfbIlNonOwnedEndorsementScans.ImageClass = Image.MFBImageInfoBase.ImageClass.Endorsement;
                                mfbIlNonOwnedEndorsementScans.Key        = m_szTargetUser;
                                mfbIlNonOwnedEndorsementScans.Refresh();

                                // show unowned and uploaded endorsements as well
                                if (student.CanAddLogbook)
                                {
                                    // allow for upload of additional scanned endorsements.
                                    mfbMultiFileUpload.Visible  = true;
                                    mfbMultiFileUpload.ImageKey = m_szTargetUser;
                                }
                            }

                            Profile pfTarget      = Profile.GetUser(m_szTargetUser);
                            string  szTargetUser  = pfTarget.UserFullName;
                            string  szEncodedUser = HttpUtility.HtmlEncode(szTargetUser);

                            lblPageHeader.Text                = String.Format(CultureInfo.CurrentCulture, Resources.Profile.EndorsementsHeader, szEncodedUser);
                            lblNewEndorsementHeader.Text      = String.Format(CultureInfo.CurrentCulture, Resources.Profile.EndorsementsNewEndorsementHeader, szEncodedUser);
                            lblExistingEndorsementHeader.Text = String.Format(CultureInfo.CurrentCulture, Resources.Profile.EndorsementsExistingEndorsementHeader, szEncodedUser);
                            lblNonOwnedHeader.Text            = String.Format(CultureInfo.CurrentCulture, Resources.Profile.EndorsementsNotOwnedEndorsementHeader, szEncodedUser);
                            mfbEditEndorsement1.TargetUser    = pfTarget;
                            mfbEditEndorsement1.Mode          = EndorsementMode.InstructorPushAuthenticated;
                        }
                        else
                        {
                            mfbEditEndorsement1.Mode = EndorsementMode.InstructorOfflineStudent;
                        }

                        Profile pf = Profile.GetUser(User.Identity.Name);

                        if (pf.Certificate.Length == 0)
                        {
                            throw new MyFlightbookValidationException(Resources.Profile.errNoCFICertificate);
                        }

                        mfbEditEndorsement1.SourceUser = pf;

                        RefreshTemplateList();

                        ViewState[keyTargetUser] = m_szTargetUser;
                    }
                }
                catch (MyFlightbookValidationException ex)
                {
                    lblError.Text                   = ex.Message;
                    pnlError.Visible                = true;
                    pnlEndorsement.Visible          = false;
                    pnlExistingEndorsements.Visible = false;
                }
            }
            else
            {
                m_szTargetUser = (string)ViewState[keyTargetUser];
            }

            // need to reconstitute the form from the template every time to ensure postback works.
            if (!pnlError.Visible && pnlEndorsement.Visible)
            {
                mfbEditEndorsement1.EndorsementID = Convert.ToInt32(hdnLastTemplate.Value, CultureInfo.InvariantCulture);
            }

            mfbEndorsementList1.Instructor = Page.User.Identity.Name;
            mfbEndorsementList1.Student    = m_szTargetUser;
            mfbEndorsementList1.RefreshEndorsements();

            if (mfbMultiFileUpload.Visible)
            {
                mfbMultiFileUpload.ProcessUploadedImages();
                if (mfbIlNonOwnedEndorsementScans.Visible)
                {
                    mfbIlNonOwnedEndorsementScans.Refresh();
                }
            }
        }