Create Album

Jul 14, 2011 at 4:41 AM

Is it possible to create an album from the beginning and pass the relevant category/subcat info at the time of creation?

I'm having difficulty even adding that information on the ChangeSettings() event.

BTW I added the URL info on my version to the Login.cs (u.URL = User.URL;)

Thanks for the great API

Jul 14, 2011 at 8:58 PM

I added a new MyUser.CreateAlbum method to get it working.

public Album CreateAlbum(string Title, bool Unique, Category cat, SubCategory subcat, Theme thm, Template tmpl, string Extras)
        {
            Album a = new Album();
            a.Title = Title;

            if (cat != null)
            {
                a.Category = cat;
            }

            if (subcat != null)
            {
                a.SubCategory = subcat;
            }

            if (tmpl != null)
            {
                a.Template = tmpl;
            }

            if (thm != null)
            {
                a.Theme = thm;
            }

            a.basic = basic;
            return a.Create(Unique, Extras);
        }

Coordinator
Jul 14, 2011 at 9:10 PM

Hi Techdrifter,

From the documentation:

Create an album (if you don’t want dups, use Unique as well)

1. In the other category:

var myAlbum = user.CreateAlbum(“myAlbum”);

with Unique: var myAlbum = user.CreateAlbum(“myAlbum”, true);


2. Create a category and then the album in it (if it exists, it won’t be duplicated, you’ll just get a category object from the site):

var myCategory = user.CreateCategory(“myCategory”);  ----> you can also use user.FindCategory("myCategory"); if you know the category exists

var myAlbum = myCategory.CreateAlbum(“myAlbum”);


3. Create a category and subcategory in it (the same goes here for dups). And then create the album in that subcategory.

var myCategory = user.CreateCategory(“myCategory”);

var mySubCategory = myCategory.CreateSubCategory(“mySubCategory”);

var myAlbum = mySubCategory.CreateAlbum(“myAlbum”);

 

 

Coordinator
Jul 14, 2011 at 9:37 PM

Also – your CreateAlbum function has some drawbacks – what happens if the category and subcategory are a mismatch (a subcategory that doesn’t exist in that category).?

I preferred to put the CreateAlbum method on Category and Subcategory because then you can make sure they exist on the site, and if not, they are created, and you can’t have a mismatch between the two. In the Create function on Album I don’t make such validations because I assume you already have the right category and subcategory (I consider it only a helper function that the user shouldn’t really use except in some weird case). If either doesn’t exist, I just put the album in the Other category. Simply because I don’t think it’s intuitive to create the category and subcategory there.

If you have suggestions or requests, don't hesitate to post them.

 

Thanks for using the framework!

Maria

Coordinator
Jul 14, 2011 at 9:42 PM

I've added a new issue for the URL info and will incorporate that to source control with the next check in. Feel free to add more issues that you find to the issue tracker!

Thanks!

Maria

Jul 14, 2011 at 9:47 PM
I haven't tested the theme/template part yet (template might be referring to the wrong one). In the app I'm using the API for, I've made sure those things match.

On Jul 14, 2011, at 3:37 PM, mariagh <notifications@codeplex.com> wrote:

From: mariagh

Also – your CreateAlbum function has some drawbacks – what happens if the category and subcategory are a mismatch (a subcategory that doesn’t exist in that category).?

I preferred to put the CreateAlbum method on Category and Subcategory because then you can make sure they exist on the site, and if not, they are created, and you can’t have a mismatch between the two. In the Create function on Album I don’t make such validations because I assume you already have the right category and subcategory (I consider it only a helper function that the user shouldn’t really use except in some weird case). If either doesn’t exist, I just put the album in the Other category. Simply because I don’t think it’s intuitive to create the category and subcategory there.

If you have suggestions or requests, don't hesitate to post them.

Thanks for using the framework!

Maria