public static ModuleRatingInfo initModuleRating(int moduleID)
        {
            // Construct a new thread post for ratings for the given module.

            Modules.ModuleInfo module = Modules.getModuleInfo(moduleID);
            Post newPost = new Post();

            newPost.Username = "******";
            newPost.Subject  = module.Title;
            newPost.Body     = "Ratings for <a href=\"" + HttpContext.Current.Request.ApplicationPath +
                               "/viewModule.aspx?moduleID=" + module.Id + "\">" + module.Title + "</a>.";
            newPost.IsLocked = true;
            newPost.ForumID  = FORUMS_ID;

            // Add the post to the forums database.

            Post returnedPost = Posts.AddPost(newPost);

            // Construct a ModuleRatingInfo object with the thread ID of the
            // actual post created.

            ModuleRatingInfo modRating = new ModuleRatingInfo();

            modRating.ModuleID = module.Id;
            modRating.ThreadID = returnedPost.ThreadID;

            ModuleRatings.createRating(modRating);

            return(modRating);
        }
 /// <summary>
 /// Initializes the non-EditControl components given a ModuleInfo object
 /// (Generic text box inputs).
 /// </summary>
 /// <param name="mi">The module's info.</param>
 protected void initGeneralControls(Modules.ModuleInfo mi)
 {
     if (mi != null)
     {
         Title.Text    = Globals.formatTextOutput(mi.Title);
         Lecture.Text  = Globals.formatTextOutput(mi.LectureSize);
         Lab.Text      = Globals.formatTextOutput(mi.LabSize);
         Exercise.Text = Globals.formatTextOutput(mi.ExerciseSize);
         Homework.Text = Globals.formatTextOutput(mi.HomeworkSize);
         Abstract.Text = Globals.formatTextOutput(mi.Abstract);
         Other.Text    = Globals.formatTextOutput(mi.OtherSize);
         Comments.Text = Globals.formatTextOutput(mi.AuthorComments);
     }
     else
     {
         Title.Text    = "";
         Lecture.Text  = "";
         Lab.Text      = "";
         Exercise.Text = "";
         Homework.Text = "";
         Abstract.Text = "";
         Other.Text    = "";
         Comments.Text = "";
     }
 }
 /// <summary>
 /// Sets members of the given data row according to the ModuleInfo associated
 /// with the BaseId member of the data row.
 /// </summary>
 /// <param name="dr">The data row to modify.</param>
 private static void initCurrentVersionRow(DataRow dr)
 {
     Modules.ModuleInfo current = Modules.getModuleCurrentVersion((int)dr["BaseId"]);
     dr["Version"] = current.Version;
     dr["Id"]      = current.Id;
     dr["Date"]    = current.Date;
 }
        /// <summary>
        /// Handle the click event for the Create Variant button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void VariantBtn_Click(object sender, System.EventArgs e)
        {
            // First, delete any existing Materials while we still
            // have access to the current Materials list
            MaterialsControl1.deleteAllMaterials(ModuleID);

            if (ModulesDdl.SelectedIndex != 0)
            {
                int moduleNum             = Convert.ToInt32(ModulesDdl.SelectedItem.Value);
                Modules.ModuleInfo module = Modules.getModuleInfo(moduleNum);
                VariantOf    = module.BaseId;
                module.Title = "Variant of " + module.Title;

                // Initialize all the controls with the original modules values.
                initEditControls(module);

                // Reset authors.  They shouldn't be copied.
                AuthorsControl1.initList(0);

                // Now, copy over all the Materials from the target
                // Module to the temp directory for this Module
                MaterialsControl1.retrieveMaterials(moduleNum);
            }
            else
            {
                VariantOf = 0;
                initEditControls(null);
            }
        }
示例#5
0
        /// <summary>
        /// Undo a check out previously made, but unlocking the module
        /// and deleting the in-progress version of it exists.
        /// </summary>
        /// <param name="moduleID">
        /// The identifier of the module for which to undo the check out.
        /// </param>
        public static void undoCheckOut(int moduleID)
        {
            Modules.setLock(moduleID, "");
            Modules.ModuleInfo mod = Modules.getModuleInfo(moduleID);

            if (mod.Status == ModuleStatus.InProgress)
            {
                Modules.remove(moduleID);
            }
        }
示例#6
0
        public int Compare(object x, object y)
        {
            try {               //Compares the submitter names of two ModuleInfo objects
                Modules.ModuleInfo obj1 = (Modules.ModuleInfo)x;
                Modules.ModuleInfo obj2 = (Modules.ModuleInfo)y;

                return(obj1.Submitter.CompareTo(obj2.Submitter));
            } catch (Exception e) {
                throw new Exception("SubmitterComparer Error");
            }
        }
        public int Compare(object x, object y)
        {
            try {               //Compares the two DateTime members of each ModuleInfo object
                Modules.ModuleInfo obj1 = (Modules.ModuleInfo)x;
                Modules.ModuleInfo obj2 = (Modules.ModuleInfo)y;

                return(obj1.Date.CompareTo(obj2.Date));
            } catch (Exception e) {
                throw new Exception("DateComparer Error");
            }
        }
        /// <summary>
        /// Initialize the variant controls.
        /// </summary>
        private void initVariantControls()
        {
            // Module drop down for variants
            ModulesDdl.DataTextField  = "Title";
            ModulesDdl.DataValueField = "Id";
            ArrayList modules = new ArrayList();

            Modules.ModuleInfo mod1 = new Modules.ModuleInfo();
            mod1.Id    = 0;
            mod1.Title = "<None Selected>";
            modules.Add(mod1);
            modules.AddRange(Modules.getAll(ModuleStatus.Approved));
            ModulesDdl.DataSource = modules;
            ModulesDdl.DataBind();
        }
        /// <summary>
        /// Initializes each of the EditControls given a ModuleInfo object.
        /// </summary>
        /// <param name="module">The module's info.</param>
        protected void initEditControls(Modules.ModuleInfo module)
        {
            initGeneralControls(module);

            foreach (IEditControl ec in editControls)
            {
                if (module == null)
                {
                    ec.initList(0);
                }
                else
                {
                    ec.initList(module.Id);
                }
            }
        }
        /// <summary>
        /// Create a ModuleInfo object.  If an existing module is being
        /// edited, the ID will be the current ID, otherwise it will
        /// be 0, indicating that it doesn't have an ID yet.
        /// </summary>
        /// <returns>An object encapsulating information about
        /// the module being uploaded.</returns>
        private Modules.ModuleInfo createModuleInfo()
        {
            Modules.ModuleInfo mi = new Modules.ModuleInfo();
            mi.Id              = ModuleID;
            mi.Title           = Globals.parseTextInput(Title.Text);
            mi.Abstract        = Globals.parseTextInput(Abstract.Text);
            mi.LectureSize     = Globals.parseTextInput(Lecture.Text);
            mi.LabSize         = Globals.parseTextInput(Lab.Text);
            mi.ExerciseSize    = Globals.parseTextInput(Exercise.Text);
            mi.HomeworkSize    = Globals.parseTextInput(Homework.Text);
            mi.OtherSize       = Globals.parseTextInput(Other.Text);
            mi.AuthorComments  = Globals.parseTextInput(Comments.Text);
            mi.CheckInComments = Globals.parseTextInput(CheckInTxt.Text);

            return(mi);
        }
        /// <summary>
        /// Handles Continue button-click events.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContinueBtn_Click(object sender, System.EventArgs e)
        {
            Modules.ModuleInfo mod        = (Modules.ModuleInfo)Session["EditModule"];
            string             queryParam = "";

            if (RadioButtonList1.SelectedIndex == 0)                 // Edit
            {
                queryParam = "?moduleID=" + mod.Id;
            }
            else                 // Delete
            {
                deleteMaterials(mod.Id);
                ModulesControl.removeModule(mod.Id);
                Session.Remove("EditModule");
            }

            Response.Redirect("editModule.aspx" + queryParam, true);
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (Session["EditModule"] == null)
            {
                Response.Redirect("editModule.aspx", true);
            }
            else
            {
                Modules.ModuleInfo mod =
                    (Modules.ModuleInfo)Session["EditModule"];

                if (mod.Title == string.Empty)
                {
                    ModuleLbl.Text = ", Untitled, ";
                }
                else
                {
                    ModuleLbl.Text = ", \"" + mod.Title + ",\" ";
                }
            }
        }
示例#13
0
        /// <summary>
        /// Check a module into version control.
        /// </summary>
        /// <param name="mi">
        /// The module to check in.
        /// </param>
        /// <param name="isUpdate">
        ///		true if editing a previously checked in version (module changes
        ///		were saved but not submitted), false if it's a new check in.
        /// </param>
        /// <returns>
        /// The identifier of the module checked in.
        /// </returns>
        public static int checkInModule(Modules.ModuleInfo mi, bool isUpdate)
        {
            int retVal = 0;

            if (isUpdate)
            {
                retVal = mi.Id;
                Modules.updateModule(mi);
            }
            else
            {
                if (mi.BaseId == 0)
                {
                    int baseID = Modules.addModuleBase(mi);
                    mi.BaseId = baseID;
                }
                retVal = Modules.addModule(mi);
            }

            return(retVal);
        }
        /// <summary>
        /// Extracts info from the ModuleInfo object and sets members of
        /// the DataRow object accordingly
        /// </summary>
        /// <param name="row">The row of data to be set.</param>
        /// <param name="module">The ModuleInfo object associated with the
        /// corresponding module.</param>
        private static void initRow(DataRow row, Modules.ModuleInfo module)
        {
            row["Id"]      = module.Id;
            row["Title"]   = module.Title;
            row["Version"] = module.Version;
            //row["Date"] = module.Date;
            row["LockedBy"] = module.LockedBy;

            if (module.LockedBy == "")
            {
                row["LockedBy"] = NotLocked;
            }

            row["BaseId"] = module.BaseId;

            if (module.Title == string.Empty)
            {
                row["Title"] = "(No Title)";
            }

            row["Status"] = module.Status;
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                try {
                    string strModuleID = Request.Params["moduleID"];

                    if (strModuleID != null)
                    {
                        int moduleID = int.Parse(Request.Params["moduleID"]);
                        Modules.ModuleInfo modInfo = Modules.getModuleInfo(moduleID);
                        ModInfo     = modInfo;
                        isSubmitter = ModulesControl.isModuleSubmitter(User.Identity.Name, modInfo.Id);
                        isAuthor    = ModulesControl.isModuleAuthor(User.Identity.Name, modInfo.Id);
                        bool isEditor = User.IsInRole(UserRole.Editor.ToString());

                        // If the user is not an editor...
                        if (!isEditor)
                        {
                            if (modInfo.Status == ModuleStatus.PreviousVersion)
                            {
                                // If the module being viewed is a previous version, display the newest
                                // version of the module, and tell the user.
                                Modules.ModuleInfo curVer = Modules.getModuleCurrentVersion(modInfo.BaseId);
                                string             newUrl = "viewModule.aspx?moduleID=" + curVer.Id;
                                lblMessage.Text = "There is a <a href=\"" + newUrl + "\">newer version</a> of the module you are trying to access.  "
                                                  + "You will be directed to it momentarily.";
                                Response.AppendHeader("Refresh", REFRESH_DELAY + "; URL=" + newUrl);
                                disableModule();
                                return;
                            }
                            else if (modInfo.Status != ModuleStatus.Approved && !isSubmitter)
                            {
                                // If it is the newest version, but has not been approved
                                // and this user is not the submitter, do not let them view
                                // the module.
                                disableModule();
                                lblMessage.Text = "Module not available.";
                                return;
                            }
                        }

                        // Modules.Size

                        string[] labels = { "Lecture",
                                            "Lab",
                                            "Exercise",
                                            "Homework",
                                            "Other" };
                        string[] sizeText = { modInfo.LectureSize,
                                              modInfo.LabSize,
                                              modInfo.ExerciseSize,
                                              modInfo.HomeworkSize,
                                              modInfo.OtherSize };

                        ArrayList sizes = new ArrayList(NUM_SIZES);

                        for (int i = 0; i < NUM_SIZES; i++)
                        {
                            if (!sizeText[i].Equals(""))
                            {
                                sizes.Add("<strong>" + labels[i] + "</strong>: " + sizeText[i]);
                            }
                        }

                        SizeRepeater.DataSource = sizes;
                        SizeRepeater.DataBind();

                        // Authors

                        AuthorsRepeater.DataSource = Authors.getAll(modInfo.Id);
                        AuthorsRepeater.DataBind();

                        // Materials
                        // Since Materials aren't displayed as simply as other
                        // areas, some modification needs to be done
                        // Retrieve the materials that the user has the access level right to acquire
                        tempMats1 = getAccessLevelFilesList(moduleID);                         //Materials.getAll( moduleID );
                        ArrayList tempMats2   = new ArrayList();
                        ArrayList knownTitles = new ArrayList();
                        int       pos         = 0;

                        foreach (Materials.MaterialInfo mi in tempMats1)
                        {
                            int    position = mi.Link.LastIndexOf('.'); // temp value for extracting the title and extension
                            string title;                               // the title part of the filename
                            string extension;                           // the extension of the filename

                            if (position == -1)
                            {
                                title     = "(No Title)";
                                extension = mi.Link;
                            }
                            else
                            {
                                title     = mi.Link.Substring(0, position);
                                extension = getFormat(mi.Link.Substring(position + 1));
                            }

                            // this is the reference to the current material that will
                            // be added to the materials repeater in the html
                            string reference = "(<a href='Materials/" + mi.ModuleID + "/" + mi.Link +
                                               "' target='_blank'>" + extension + "</a>)";

                            // see if we've already come across this title
                            int index = knownTitles.IndexOf(title.ToLower());

                            if (index == -1)
                            {
                                // Means that the title hasn't already been found,
                                // so we need to add it as a new Material group
                                tempMats2.Add(new Materials.MaterialInfo(mi.Id, mi.IdentInfo, reference,
                                                                         mi.ModuleID, mi.RatingImage, mi.Rating,
                                                                         mi.AccessFlag));
                                knownTitles.Add(title.ToLower());
                            }
                            else
                            {
                                // Means that the title has already been found, so we
                                // need to add a link for this extra Material to the
                                // appropriate existing Material group
                                ((Materials.MaterialInfo)(tempMats2[index])).Link += " " + reference;
                            }
                        }

                        MaterialsRepeater.DataSource = tempMats2;
                        MaterialsRepeater.DataBind();

                        // Categories

                        CategoriesRepeater.DataSource = Categories.getAll(modInfo.Id);
                        CategoriesRepeater.DataBind();

                        // Prerequisites

                        PrereqRepeater.DataSource = Prerequisites.getAll(modInfo.Id);
                        PrereqRepeater.DataBind();

                        // Objectives

                        ObjectivesRepeater.DataSource = Objectives.getAll(modInfo.Id);
                        ObjectivesRepeater.DataBind();

                        // Topics

                        TopicsRepeater.DataSource = Topics.getAll(modInfo.Id);
                        TopicsRepeater.DataBind();

                        // Resources

                        IList resourcesList = Resources.getAll(modInfo.Id);

                        // If there are no resources, display text that says so.
                        if (resourcesList.Count == 0)
                        {
                            ResourcesRepeater.Controls.Add(new LiteralControl("<p>No resources.</p>"));
                        }
                        else
                        {
                            ResourcesRepeater.DataSource = resourcesList;
                            ResourcesRepeater.DataBind();
                        }

                        // See Also

                        IList seeAlsoList = SeeAlso.getAll(modInfo.Id);

                        // If there are no alternate modules, display text that says so.
                        if (seeAlsoList.Count == 0)
                        {
                            SeeAlsoRepeater.Controls.Add(new LiteralControl("<p>No alternate modules.</p>"));
                        }
                        else
                        {
                            SeeAlsoRepeater.DataSource = seeAlsoList;
                            SeeAlsoRepeater.DataBind();
                        }

                        // Ratings

                        if (modInfo.Status == ModuleStatus.Approved)
                        {
                            ModuleRatingInfo mci = ModuleRatings.getRating(modInfo.Id);
                            RateModuleControl1.RatingInfo = mci;

                            // Submitters and authors can't rate their own modules.
                            if (isSubmitter || isAuthor)
                            {
                                RateModuleControl1.AddRatingEnabled = false;
                                RatingsMessage.Text = "<p>You may not rate a module that " +
                                                      "you have submitted or are listed as an author of.</p>";
                            }
                            else
                            {
                                Rating rating = ModuleRatingsControl.getRatingForUser(User.Identity.Name, mci);
                                RateModuleControl1.UserRating = rating;
                            }
                        }
                        else
                        {
                            disableRatings();
                        }

                        // Related Modules
                        IList related = ModuleGroups.getRelatedModules(modInfo.BaseId);

                        if (related.Count == 0)
                        {
                            H21.Visible = false;
                        }
                        else
                        {
                            RelatedRepeater.DataSource = related;
                            RelatedRepeater.DataBind();
                        }
                    }
                    else
                    {
                        lblMessage.Text =
                            "An error occurred while attempting to get the requested module." +
                            "  No module was specified.  <a href=\"browseModules.aspx\">Browse</a>" +
                            " or <a href=\"search.aspx\">search</a> to select a module to view.";
                    }
                } catch (Exception ex) {
                    lblMessage.Text =
                        "An error occurred while attempting to get the requested module." +
                        "  " + ex.Message + " " + ex.StackTrace;
                }
            }
        }
 /// <summary>
 /// Disable the viewing of the module.
 /// </summary>
 private void disableModule()
 {
     ModInfo = null;
     disableRatings();
 }
        private void Page_Load(Object sender, EventArgs e)
        {
            ErrorMessage.Text = "";

            editControls[0] = CategoriesControl1;
            editControls[1] = AuthorsControl1;
            editControls[2] = PrerequisitesControl1;
            editControls[3] = ObjectivesControl1;
            editControls[4] = TopicsControl1;
            editControls[5] = MaterialsControl1;
            editControls[6] = ResourcesControl1;
            editControls[7] = SeeAlsoControl1;

            if (!IsPostBack)
            {
                DateLbl.Text = DateTime.Now.ToShortDateString();
                VariantOf    = -1;
                Modules.ModuleInfo module = null;

                // Determine the edit type from moduleID param.
                if (Request.QueryString["moduleID"] != null)
                {
                    ModuleID = Convert.ToInt32(Request.QueryString["moduleID"]);

                    // Submitters can only edit their own modules
                    string modSubmitter = (Modules.getModuleInfo(ModuleID)).Submitter;
                    if (!User.IsInRole(UserRole.Admin.ToString()) &&
                        !User.Identity.Name.Equals(modSubmitter))
                    {
                        string message = "You can't edit modules you didn't submit.";
                        Response.Redirect("MyAccount.aspx?message=" + message, true);
                    }                     // end submitter verification

                    if (Session["EditModule"] != null)
                    {
                        module = (Modules.ModuleInfo)Session["EditModule"];
                        Session.Remove("EditModule");
                    }
                    else
                    {
                        module = Modules.getModuleInfo(ModuleID);
                    }

                    determineEditType(module.Status);
                }
                else
                {
                    ModuleID       = 0;
                    ModuleEditType = EditType.New;
                }

                switch (ModuleEditType)
                {
                case EditType.InProgress:
                    if (module.IsRevision)
                    {
                        VariantPanel.Visible = false;
                        Title.Enabled        = false;
                    }

                    initEditControls(module);
                    initVariantControls();
                    break;

                case EditType.Approved:
                    VariantPanel.Visible = false;
                    Title.Enabled        = false;
                    initEditControls(module);
                    initVariantControls();
                    break;

                case EditType.New:
                    IList inProgMods =
                        Modules.getModulesBySubmitter(User.Identity.Name, ModuleStatus.InProgress);

                    // Ensure there aren't any in progress modules.
                    if (inProgMods.Count > 0)
                    {
                        Session["EditModule"] = inProgMods[0];
                        Response.Redirect("uploadModule.aspx", true);
                    }
                    else
                    {
                        ModuleID = 0;
                        initEditControls(module);
                        initVariantControls();
                        deleteTempMaterials();
                    }

                    break;
                }

                VariantBtn.Attributes.Add("onClick", "if ( !confirm('This will overwrite any existing module information with the information from the selected module (or clear it if none is selected).  Do you want to continue?') ) return false;");

                if (ModuleEditType != EditType.New)
                {
                    CancelBtn.Attributes.Add("onClick", "if ( !confirm('Discard all changes and remove your lock on this module?') ) return false;");
                    CancelBtnTop.Attributes.Add("onClick", "if ( !confirm('Discard all changes and remove your lock on this module?') ) return false;");
                }
                else
                {
                    CancelBtn.Visible    = false;
                    CancelBtnTop.Visible = false;
                }

                UploadStep = 0;
                toggleButtonsAndPanels(0);
            }
        }
        /// <summary>
        /// Save a new module or changes to an existing module.
        /// </summary>
        /// <param name="status">The status to designate for the module.</param>
        private Modules.ModuleInfo saveModule(ModuleStatus status)
        {
            // tells whether old data exists that needs to be
            // removed before adding any new data
            bool removePrevious = false;

            // tells whether user is just updating an existing
            // module or if they want to create a new module
            // (possibly a new version of an existing module)
            bool isUpdate = false;

            Modules.ModuleInfo mi = createModuleInfo();

            ModuleID           = mi.Id;
            ErrorMessage.Text += "Getting base ID for module: " + ModuleID;

            if (ModuleID > 0)
            {
                mi.BaseId = Modules.getModuleInfo(ModuleID).BaseId;
            }
            else
            {
                mi.BaseId = 0;
            }

            mi.Status      = status;
            mi.Submitter   = User.Identity.Name;
            mi.SubmitterID = UserAccounts.getUserInfo(User.Identity.Name).SubmitterID;

            switch (ModuleEditType)
            {
            case EditType.New:

                isUpdate = false;

                break;

            case EditType.InProgress:

                isUpdate       = true;
                removePrevious = true;

                break;

            case EditType.Approved:
                Modules.ModuleInfo oldModule = Modules.getModuleInfo(ModuleID);
                mi.BaseId = oldModule.BaseId;
                // If this module was previously Approved, and an admin changed it,
                // just update the module without creating a new version.
                if (User.Identity.IsAuthenticated && User.IsInRole(UserRole.Admin.ToString()))
                {
                    string modSubmitter = oldModule.Submitter;
                    // If this module is the admin's own, behave as if not an admin.
                    // Admins deserve multiple versions too.
                    if (User.Identity.Name.Equals(modSubmitter))
                    {
                        isUpdate   = false;
                        mi.Version = oldModule.Version + 1;
                    }
                    else
                    {
                        mi.Submitter   = modSubmitter;
                        mi.SubmitterID = oldModule.SubmitterID;

                        isUpdate   = true;
                        mi.Version = oldModule.Version;
                    }
                }
                // If this module was previously Approved, and a non-admin changed
                // it, create a new version of the module, and check it out accordingly.
                else
                {
                    isUpdate = false;
                    MaterialsControl1.retrieveMaterials(oldModule.Id);
                    mi.Version = oldModule.Version + 1;
                }
                removePrevious = true;

                break;
            }

            try
            {
                ModuleID = ModulesControl.checkInModule(mi, isUpdate);

                ErrorMessage.Text += " Assigned ModuleID = " + ModuleID + ".  ";

                mi.Id = ModuleID;

                foreach (IEditControl ec in editControls)
                {
                    ec.insertAll(ModuleID, removePrevious);
                }

                /** HANDLE THE VARIANTS **/

                // is true if this module is new OR a variant is chosen (including <None>)
                if (VariantOf != -1)
                {
                    int groupID = ModuleGroups.getGroupID(mi.BaseId);

                    // if this module was reset as a variant of the same module
                    // as before, or if it was set as a variant of a module in
                    // the same group as it already is in, do nothing
                    if (groupID != -1 && groupID == ModuleGroups.getGroupID(VariantOf))
                    {
                    }
                    // if this module was already in a group by itself, and the
                    // user tries to put it in a new group by itself, ignore
                    // the request and do nothing
                    else if (groupID != -1 && VariantOf == 0 && ModuleGroups.getRelatedModules(mi.BaseId).Count == 0)
                    {
                    }
                    else
                    {
                        // if <None> was chosen, add this module to its own module group
                        if (VariantOf == 0)
                        {
                            ModuleGroups.addToNew(mi.BaseId);
                        }
                        // else add this module to the group that was chosen
                        // SQL code resolves duplicates
                        else
                        {
                            ModuleGroups.addToExisting(mi.BaseId, VariantOf);
                        }
                    }
                }
                else
                {
                    // If the module was not a variant, add this module to its own module group
                    ModuleGroups.addToNew(mi.BaseId);
                }
            }
            catch (Exception e)
            {
                string message = "An error occurred while saving your module.";

                // If a new module was being created and there was an error, remove
                // the module (and by cascading, any added pieces).
                if (ModuleEditType == EditType.New && ModuleID != 0)
                {
                    ModulesControl.removeModule(ModuleID);
                    message += "  Module was not saved.  Review the module and try to resubmit it.";
                }
                else
                {
                    message       += "  All of your changes were not saved.  Review the module and try to resubmit it.";
                    ModuleEditType = EditType.InProgress;
                }

                // send an email to admins reporting the error
                Email msg = Emails.getEmail(EmailType.CriticalError);
                Emails.formatEmail(msg, mi.Submitter, mi.Id);
                Emails.formatEmailBody(msg, e.StackTrace + "::" + e.Message);
                MailMessage mail = Emails.constructErrorMessage(msg, Globals.AdminsEmail);
                SmtpMail.SmtpServer = AspNetForums.Components.Globals.SmtpServer;
                SmtpMail.Send(mail);

                message += " An e-mail reporting the error has been sent to the SWEnet Administrators.";
                throw new Exception(message, e);
            }

            return(mi);
        }
示例#19
0
        /// <summary>
        /// Mark a module as approved and update lock state.
        /// </summary>
        /// <param name="moduleID">The identifier of the module to approve.</param>
        public static void approveModule(int moduleID)
        {
            // Mark module as approved and unlock it.
            Modules.updateModuleStatus(moduleID, ModuleStatus.Approved);
            Modules.setLock(moduleID, "");

            // If there was a previous version, mark it as PreviousVersion.

            Modules.ModuleInfo mod = Modules.getModuleInfo(moduleID);

            if (mod.Version > 1)
            {
                IList versions = Modules.getModuleVersions(mod.BaseId, true);
                Modules.updateModuleStatus(((Modules.ModuleInfo)versions[versions.Count - 2]).Id,
                                           ModuleStatus.PreviousVersion);
            }
            else
            {
                string newID;
                string lastID           = Modules.getLastIDbySubmitter(mod.Submitter);
                int    currentYear      = System.DateTime.Now.Year;
                string moduleIdentifier = mod.BaseId == 0 ? "" : DBAdapter.Modules.getModuleIdentifierByBaseID(mod.BaseId);

                // If the baseID for this module already had a module identifier, reuse it
                if (moduleIdentifier != "")
                {
                    newID = moduleIdentifier;
                }
                else if (lastID != "")
                {
                    // if not, we need to set the identifier...
                    // if the submitter has submitted modules before, the next identifier depends on the
                    // identifier of the last module they submitted
                    int pos1 = lastID.IndexOf('.');
                    int pos2 = lastID.LastIndexOf('.');
                    int year = int.Parse(lastID.Substring(pos1 + 1, pos2 - pos1 - 1));

                    if (year == currentYear)
                    {
                        // Get the last module number and increment it
                        int moduleNum = int.Parse(lastID.Substring(pos2 + 1));
                        newID = lastID.Substring(0, pos2 + 1) + (moduleNum + 1);
                    }
                    else
                    {
                        // If the last module that was submitted by this
                        // submitter was in a previous year, use this year
                        // and the module number 1
                        newID = lastID.Substring(0, pos1 + 1) + currentYear + ".1";
                    }
                }
                else
                {
                    // If lastID was an empty string, the submitter hasn't submitted
                    // any modules before, so we need to create a new identifier
                    newID = mod.Submitter + "." + currentYear + ".1";
                }

                Modules.setModuleIdentifier(mod.BaseId, newID);
                Modules.setLastIDbySubmitter(mod.Submitter, newID);
            }

            ModuleRatingsControl.initModuleRating(moduleID);
        }