Files
server/src/Core/Models/Table/Organization.cs

96 lines
2.9 KiB
C#
Raw Normal View History

using System;
using Bit.Core.Utilities;
using Bit.Core.Enums;
using Bit.Core.Services;
using Bit.Core.Exceptions;
2017-03-08 21:45:08 -05:00
namespace Bit.Core.Models.Table
{
2017-07-14 09:05:15 -04:00
public class Organization : ITableObject<Guid>, ISubscriber, IStorable, IStorableSubscriber, IRevisable
{
public Guid Id { get; set; }
public string Name { get; set; }
2017-04-04 12:57:50 -04:00
public string BusinessName { get; set; }
public string BillingEmail { get; set; }
public string Plan { get; set; }
public PlanType PlanType { get; set; }
public short? Seats { get; set; }
2017-04-27 09:19:30 -04:00
public short? MaxCollections { get; set; }
2017-05-08 14:22:40 -04:00
public bool UseGroups { get; set; }
2017-05-20 15:31:16 -04:00
public bool UseDirectory { get; set; }
2017-07-07 14:08:30 -04:00
public bool UseTotp { get; set; }
public bool SelfHost { get; set; }
public long? Storage { get; set; }
public short? MaxStorageGb { get; set; }
public GatewayType? Gateway { get; set; }
public string GatewayCustomerId { get; set; }
public string GatewaySubscriptionId { get; set; }
2017-04-10 22:33:39 -04:00
public bool Enabled { get; set; } = true;
public string LicenseKey { get; set; }
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
public void SetNewId()
{
if(Id == default(Guid))
{
Id = CoreHelpers.GenerateComb();
}
}
2017-07-06 14:55:58 -04:00
public string BillingEmailAddress()
{
return BillingEmail;
}
public string BillingName()
{
return BusinessName;
}
public long StorageBytesRemaining()
{
if(!MaxStorageGb.HasValue)
{
return 0;
}
2017-07-06 14:55:58 -04:00
return StorageBytesRemaining(MaxStorageGb.Value);
}
public long StorageBytesRemaining(short maxStorageGb)
{
var maxStorageBytes = maxStorageGb * 1073741824L;
if(!Storage.HasValue)
{
return maxStorageBytes;
}
return maxStorageBytes - Storage.Value;
}
public IPaymentService GetPaymentService(GlobalSettings globalSettings)
{
if(Gateway == null)
{
throw new BadRequestException("No gateway.");
}
IPaymentService paymentService = null;
switch(Gateway)
{
case GatewayType.Stripe:
paymentService = new StripePaymentService();
break;
case GatewayType.Braintree:
paymentService = new BraintreePaymentService(globalSettings);
break;
default:
throw new NotSupportedException("Unsupported gateway.");
}
return paymentService;
}
}
}