Пример #1
0
        public void GetCategoriesForIdList()
        {
            MPRSession   session = MPRController.StartSession();
            List <Int64> ids     = new List <Int64>();

            ids.Add(5); ids.Add(7); ids.Add(8);
            IList <MPCategory> categories = MPRController.RetrieveByIdList <MPCategory>(session, ids);

            Assert.That(categories.Count, Is.EqualTo(3));

            foreach (MPCategory category in categories)
            {
                System.Console.WriteLine("{0} : {1} : {2}", category.Id, category.Name, category.Description);
            }
        }
Пример #2
0
        /// <summary>
        /// Handle the actual creation of the entity
        /// </summary>
        /// <param name="filename">the name of the local file</param>
        /// <returns>success or failure</returns>
        protected bool AddFileToRepository(string filename)
        {
            MPRSession session = MPRController.StartSession();
            MPUser     user    = SessionUtils.GetCurrentUser();

            MPItem item = new MPItem();

            item.Name = titleTextBox.Text;

            Int64 typeId;

            if (!Int64.TryParse(typesList.SelectedValue, out typeId))
            {
                return(UploadFail(String.Format("Invalid item type {0}", typesList.SelectedValue)));
            }

            item.Type = MPRController.RetrieveById <MPItemType>(session, typeId);
            if (item.Type == null)
            {
                return(UploadFail(String.Format("Unable to find item type {0} ({1})", typesList.SelectedItem, typeId)));
            }

            List <Int64> categoryIds = new List <Int64>();

            foreach (ListItem categoryItem in categoriesList.Items)
            {
                if (categoryItem.Selected)
                {
                    Int64 id;
                    if (Int64.TryParse(categoryItem.Value, out id))
                    {
                        categoryIds.Add(id);
                    }
                }
            }
            IList <MPCategory> categories = MPRController.RetrieveByIdList <MPCategory>(session, categoryIds);

            foreach (MPCategory category in categories)
            {
                item.Categories.Add(category);
            }

            item.Description       = descriptionTextBox.Text;
            item.DescriptionShort  = descriptionShortTextBox.Text;
            item.License           = licenseTextBox.Text;
            item.LicenseMustAccept = licenseMustAccessCheckBox.Checked;
            item.Author            = authorTextBox.Text;
            item.Homepage          = homepageTextbox.Text;

            item.Tags = MPRController.GetTags(session, tagsTextBox.Text);

            // create ItemVersion
            MPItemVersion itemVersion = new MPItemVersion();

            itemVersion.Item              = item;
            itemVersion.Uploader          = user;
            itemVersion.DevelopmentStatus = (MPItemVersion.MPDevelopmentStatus)Enum.Parse(typeof(MPItemVersion.MPDevelopmentStatus), developmentStatusDropDownList.SelectedValue);
            itemVersion.MPVersionMin      = mpVersionMinTextBox.Text;
            itemVersion.MPVersionMax      = mpVersionMaxTextBox.Text;
            itemVersion.Version           = versionTextBox.Text;

            MPFile mpfile = new MPFile();

            mpfile.ItemVersion = itemVersion;
            mpfile.Filename    = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName);
            mpfile.Location    = filename;

            itemVersion.Files.Add(mpfile);

            item.Versions.Add(itemVersion);

            // Save item (and sub-items) to database
            try
            {
                MPRController.Save <MPItem>(session, item);
                MPRController.EndSession(session, true);
            }
            catch (Exception ex)
            {
                MPRController.EndSession(session, false);
                return(UploadFail("Unable to save item: " + ex.ToString()));
            }

            return(true);
        }