DocSpace-client/products/ASC.CRM/Server/Classes/CRMSettings.cs

195 lines
7.0 KiB
C#
Raw Normal View History

2020-03-02 15:38:31 +00:00
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
2021-03-19 16:56:26 +00:00
using System;
2021-03-23 15:41:56 +00:00
using System.Text.Json.Serialization;
2021-03-19 16:56:26 +00:00
using ASC.Common;
2020-03-02 15:38:31 +00:00
using ASC.Core.Common.Settings;
2021-03-19 16:56:26 +00:00
using Microsoft.Extensions.Configuration;
2020-04-14 14:35:52 +00:00
using Microsoft.Extensions.DependencyInjection;
2020-03-02 15:38:31 +00:00
namespace ASC.Web.CRM.Classes
{
public class SMTPServerSetting
{
public SMTPServerSetting()
{
}
public SMTPServerSetting(ASC.Core.Configuration.SmtpSettings smtpSettings)
{
Host = smtpSettings.Host;
Port = smtpSettings.Port;
EnableSSL = smtpSettings.EnableSSL;
RequiredHostAuthentication = smtpSettings.EnableAuth;
HostLogin = smtpSettings.CredentialsUserName;
HostPassword = smtpSettings.CredentialsUserPassword;
SenderDisplayName = smtpSettings.SenderDisplayName;
SenderEmailAddress = smtpSettings.SenderAddress;
}
2021-03-19 16:56:26 +00:00
public String Host { get; set; }
2020-03-02 15:38:31 +00:00
public int Port { get; set; }
public bool EnableSSL { get; set; }
public bool RequiredHostAuthentication { get; set; }
public String HostLogin { get; set; }
public String HostPassword { get; set; }
public String SenderDisplayName { get; set; }
public String SenderEmailAddress { get; set; }
}
2021-03-02 16:29:07 +00:00
[Scope]
2020-03-02 15:38:31 +00:00
public class InvoiceSetting
{
2021-03-23 15:41:56 +00:00
public InvoiceSetting()
{
}
2020-04-02 19:42:03 +00:00
public InvoiceSetting(IConfiguration configuration)
2020-03-02 15:38:31 +00:00
{
2020-04-14 18:59:32 +00:00
Configuration = configuration;
2020-03-02 15:38:31 +00:00
}
2020-04-02 19:42:03 +00:00
public IConfiguration Configuration { get; }
public InvoiceSetting DefaultSettings
2020-03-02 15:38:31 +00:00
{
get
{
2020-04-02 19:42:03 +00:00
return new InvoiceSetting(Configuration)
2021-03-19 16:56:26 +00:00
{
Autogenerated = true,
Prefix = Configuration["crm:invoice:prefix"] ?? "INV-",
Number = "0000001",
Terms = String.Empty,
CompanyName = String.Empty,
CompanyLogoID = 0,
CompanyAddress = String.Empty
};
2020-03-02 15:38:31 +00:00
}
}
2021-03-19 16:56:26 +00:00
public bool Autogenerated { get; set; }
2020-03-02 15:38:31 +00:00
public String Prefix { get; set; }
public String Number { get; set; }
public String Terms { get; set; }
public String CompanyName { get; set; }
public Int32 CompanyLogoID { get; set; }
public String CompanyAddress { get; set; }
}
2021-05-05 14:09:05 +00:00
public class CrmSettings : ISettings
2020-03-02 15:38:31 +00:00
{
2021-05-05 14:09:05 +00:00
public CrmSettings()
2020-04-02 19:42:03 +00:00
{
2021-03-23 15:41:56 +00:00
2020-04-02 19:42:03 +00:00
}
2021-03-23 15:41:56 +00:00
public Guid ID
2020-03-02 15:38:31 +00:00
{
2021-03-23 15:41:56 +00:00
get { return new Guid("fdf39b9a-ec96-4eb7-aeab-63f2c608eada"); }
2020-03-02 15:38:31 +00:00
}
[JsonPropertyName("SMTPServerSetting")]
2020-03-02 15:38:31 +00:00
public SMTPServerSetting SMTPServerSettingOld { get; set; }
public InvoiceSetting InvoiceSetting { get; set; }
public Guid WebFormKey { get; set; }
[JsonPropertyName("DefaultCurrency")]
2021-03-23 15:41:56 +00:00
public String DefaultCurrency { get; set; }
[JsonPropertyName("ChangeContactStatusGroupAuto")]
2021-03-09 15:37:16 +00:00
public string ChangeContactStatusGroupAutoDto { get; set; }
2020-03-02 15:38:31 +00:00
[JsonIgnore]
2020-03-02 15:38:31 +00:00
public Boolean? ChangeContactStatusGroupAuto
{
2021-03-09 15:37:16 +00:00
get { return string.IsNullOrEmpty(ChangeContactStatusGroupAutoDto) ? null : (bool?)bool.Parse(ChangeContactStatusGroupAutoDto); }
set { ChangeContactStatusGroupAutoDto = value.HasValue ? value.Value.ToString().ToLowerInvariant() : null; }
2020-03-02 15:38:31 +00:00
}
[JsonPropertyName("AddTagToContactGroupAuto")]
2021-03-09 15:37:16 +00:00
public string AddTagToContactGroupAutoDto { get; set; }
2020-03-02 15:38:31 +00:00
2021-03-23 15:41:56 +00:00
[JsonIgnore]
2020-03-02 15:38:31 +00:00
public Boolean? AddTagToContactGroupAuto
{
2021-03-09 15:37:16 +00:00
get { return string.IsNullOrEmpty(AddTagToContactGroupAutoDto) ? null : (bool?)bool.Parse(AddTagToContactGroupAutoDto); }
set { AddTagToContactGroupAutoDto = value.HasValue ? value.Value.ToString().ToLowerInvariant() : null; }
2020-03-02 15:38:31 +00:00
}
[JsonPropertyName("WriteMailToHistoryAuto")]
2020-03-02 15:38:31 +00:00
public Boolean WriteMailToHistoryAuto { get; set; }
[JsonPropertyName("IsConfiguredPortal")]
2020-03-02 15:38:31 +00:00
public bool IsConfiguredPortal { get; set; }
[JsonPropertyName("IsConfiguredSmtp")]
2020-03-02 15:38:31 +00:00
public bool IsConfiguredSmtp { get; set; }
2020-04-02 19:42:03 +00:00
public ISettings GetDefault(IServiceProvider serviceProvider)
2020-03-02 15:38:31 +00:00
{
2021-03-23 15:41:56 +00:00
var currencyProvider = serviceProvider.GetService<CurrencyProvider>();
var configuration = serviceProvider.GetService<IConfiguration>();
2020-03-02 15:38:31 +00:00
var languageName = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
2021-03-23 15:41:56 +00:00
var findedCurrency = currencyProvider.GetAll().Find(item => String.Compare(item.CultureName, languageName, true) == 0);
2021-03-19 16:56:26 +00:00
2021-05-05 14:09:05 +00:00
return new CrmSettings()
2021-03-19 16:56:26 +00:00
{
2021-03-23 15:41:56 +00:00
DefaultCurrency = findedCurrency != null ? findedCurrency.Abbreviation : "USD",
2021-03-19 16:56:26 +00:00
IsConfiguredPortal = false,
ChangeContactStatusGroupAuto = null,
AddTagToContactGroupAuto = null,
WriteMailToHistoryAuto = false,
2021-03-23 15:41:56 +00:00
WebFormKey = Guid.Empty,
InvoiceSetting = new InvoiceSetting(configuration).DefaultSettings
2021-03-19 16:56:26 +00:00
};
2020-03-02 15:38:31 +00:00
}
}
2021-05-05 14:09:05 +00:00
public class CrmReportSampleSettings : ISettings
2020-03-02 15:38:31 +00:00
{
[JsonPropertyName("NeedToGenerate")]
2020-03-02 15:38:31 +00:00
public bool NeedToGenerate { get; set; }
2020-04-02 19:42:03 +00:00
public Guid ID
2020-03-02 15:38:31 +00:00
{
get { return new Guid("{54CD64AD-E73B-45A3-89E4-4D42A234D7A3}"); }
}
2020-04-02 19:42:03 +00:00
public ISettings GetDefault(IServiceProvider serviceProvider)
2020-03-02 15:38:31 +00:00
{
2021-05-05 14:09:05 +00:00
return new CrmReportSampleSettings { NeedToGenerate = true };
2020-03-02 15:38:31 +00:00
}
}
}