73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using Swarmops.Basic.Types.Communications;
|
|
using Swarmops.Common.Enums;
|
|
using Swarmops.Database;
|
|
using Swarmops.Logic.Structure;
|
|
using Swarmops.Logic.Swarm;
|
|
|
|
namespace Swarmops.Logic.Communications
|
|
{
|
|
public class AutoMail : BasicAutoMail
|
|
{
|
|
private AutoMail() : base (null)
|
|
{
|
|
} // Private constructor
|
|
|
|
private AutoMail (BasicAutoMail basic) : base (basic)
|
|
{
|
|
}
|
|
|
|
public new string Body
|
|
{
|
|
get { return base.Body; }
|
|
|
|
set
|
|
{
|
|
base.Body = value;
|
|
SwarmDb.GetDatabaseForWriting().SetAutoMail (this); // saves changes
|
|
}
|
|
}
|
|
|
|
|
|
internal static AutoMail FromBasic (BasicAutoMail basic)
|
|
{
|
|
return new AutoMail (basic);
|
|
}
|
|
|
|
|
|
public static AutoMail FromTypeOrganizationAndGeography (AutoMailType type, Organization org, Geography geo)
|
|
{
|
|
BasicAutoMail basic = SwarmDb.GetDatabaseForReading().GetAutoMail (type, org.Identity, geo.Identity);
|
|
|
|
if (basic == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (basic.Body.Trim().Length < 3)
|
|
{
|
|
return null; // If there is no body, there is no mail
|
|
}
|
|
|
|
return FromBasic (basic);
|
|
}
|
|
|
|
|
|
public static AutoMail Create (AutoMailType type, Organization org, Geography geo,
|
|
Person author, string title, string body)
|
|
{
|
|
SwarmDb.GetDatabaseForWriting().SetAutoMail (type, org.Identity, geo.Identity,
|
|
author == null ? 0 : author.Identity, title, body);
|
|
return FromTypeOrganizationAndGeography (type, org, geo);
|
|
}
|
|
|
|
|
|
// For the time being, only the body and intro have "Set" functions, as they're the only fields
|
|
// saveable from
|
|
// the interface. This is supposed to grow to include title and authorId too.
|
|
|
|
public static BasicAutoMail[] GetAllForMigration()
|
|
{
|
|
return SwarmDb.GetDatabaseForReading().GetAllAutoMailsForMigration();
|
|
}
|
|
}
|
|
} |