82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
using System;
|
|
using Swarmops.Basic.Types;
|
|
using Swarmops.Database;
|
|
|
|
namespace Swarmops.Logic.Media
|
|
{
|
|
public class Reporter : BasicReporter, IComparable
|
|
{
|
|
private MediaCategories mediaCategories;
|
|
|
|
private Reporter(BasicReporter original) : base(original)
|
|
{
|
|
}
|
|
|
|
public MediaCategories MediaCategories
|
|
{
|
|
get
|
|
{
|
|
if (MediaCategoryIds == null)
|
|
{
|
|
MediaCategoryIds = SwarmDb.GetDatabaseForReading().GetReporterMediaCategories(Identity);
|
|
}
|
|
|
|
if (this.mediaCategories == null)
|
|
{
|
|
if (MediaCategoryIds.Length > 0)
|
|
{
|
|
this.mediaCategories = MediaCategories.FromIdentities(MediaCategoryIds);
|
|
}
|
|
else
|
|
{
|
|
this.mediaCategories = new MediaCategories();
|
|
}
|
|
}
|
|
|
|
return this.mediaCategories;
|
|
}
|
|
}
|
|
|
|
public static Reporter Create(string name, string email, string[] categories)
|
|
{
|
|
Reporter reporter = FromIdentity(SwarmDb.GetDatabaseForWriting().CreateReporter(name, email));
|
|
|
|
foreach (string category in categories)
|
|
{
|
|
SwarmDb.GetDatabaseForWriting().CreateReporterMediaCategory(reporter.Identity, category);
|
|
}
|
|
|
|
return reporter;
|
|
}
|
|
|
|
|
|
public void Delete()
|
|
{
|
|
SwarmDb.GetDatabaseForWriting().DeleteReporter(Identity);
|
|
|
|
// After this operation, the object is no longer valid.
|
|
}
|
|
|
|
|
|
public static Reporter FromBasic(BasicReporter basic)
|
|
{
|
|
return new Reporter(basic);
|
|
}
|
|
|
|
public static Reporter FromIdentity(int identity)
|
|
{
|
|
return FromBasic(SwarmDb.GetDatabaseForReading().GetReporter(identity));
|
|
}
|
|
|
|
#region IComparable Members
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
Reporter otherReporter = (Reporter) obj;
|
|
|
|
return Name.CompareTo(otherReporter.Name);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |