2020-04-16 19:41:37 +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 ;
using System.Collections.Generic ;
using System.Linq ;
using System.Security ;
2021-05-28 15:18:55 +00:00
using System.Text.Json ;
2022-02-10 18:25:40 +00:00
using System.Threading.Tasks ;
2021-03-19 16:56:26 +00:00
2021-03-10 15:38:56 +00:00
using ASC.Api.CRM ;
2020-04-16 19:41:37 +00:00
using ASC.Common.Threading.Progress ;
2021-03-10 15:38:56 +00:00
using ASC.Core.Common.Settings ;
2021-03-09 15:37:16 +00:00
using ASC.CRM.ApiModels ;
2020-04-16 19:41:37 +00:00
using ASC.CRM.Core ;
2021-03-10 15:38:56 +00:00
using ASC.CRM.Core.Dao ;
2020-04-16 19:41:37 +00:00
using ASC.CRM.Core.Entities ;
2020-04-18 17:49:09 +00:00
using ASC.CRM.Core.Enums ;
using ASC.CRM.Resources ;
2022-05-19 15:47:59 +00:00
using ASC.MessagingSystem.Core ;
2020-04-16 19:41:37 +00:00
using ASC.Web.Core.Utility ;
using ASC.Web.CRM.Classes ;
2021-03-02 16:29:07 +00:00
2021-03-19 16:56:26 +00:00
using AutoMapper ;
2020-04-16 19:41:37 +00:00
2021-03-24 15:55:47 +00:00
using Microsoft.AspNetCore.Mvc ;
2021-03-10 15:38:56 +00:00
namespace ASC.CRM.Api
2020-04-16 19:41:37 +00:00
{
2021-03-10 15:38:56 +00:00
public class UtilsController : BaseApiController
2020-04-16 19:41:37 +00:00
{
2021-03-23 15:41:56 +00:00
private readonly ExportToCsv _exportToCsv ;
private readonly ImportFromCSV _importFromCSV ;
private readonly Global _global ;
private readonly OrganisationLogoManager _organisationLogoManager ;
private readonly ImportFromCSVManager _importFromCSVManager ;
private readonly InvoiceSetting _invoiceSetting ;
private readonly SettingsManager _settingsManager ;
private readonly CurrencyProvider _currencyProvider ;
private readonly MessageService _messageService ;
2021-05-05 14:09:05 +00:00
public UtilsController ( CrmSecurity crmSecurity ,
2021-03-10 15:38:56 +00:00
DaoFactory daoFactory ,
MessageService messageService ,
SettingsManager settingsManager ,
CurrencyProvider currencyProvider ,
InvoiceSetting invoiceSetting ,
ImportFromCSVManager importFromCSVManager ,
OrganisationLogoManager organisationLogoManager ,
Global global ,
2021-03-13 18:00:08 +00:00
ImportFromCSV importFromCSV ,
2021-03-19 16:56:26 +00:00
ExportToCsv exportToCsv ,
IMapper mapper )
2021-04-06 17:33:28 +00:00
: base ( daoFactory , crmSecurity , mapper )
2021-03-10 15:38:56 +00:00
{
2021-03-23 15:41:56 +00:00
_messageService = messageService ;
_currencyProvider = currencyProvider ;
_settingsManager = settingsManager ;
_invoiceSetting = invoiceSetting ;
_importFromCSVManager = importFromCSVManager ;
_organisationLogoManager = organisationLogoManager ;
_global = global ;
_importFromCSV = importFromCSV ;
_exportToCsv = exportToCsv ;
2021-03-10 15:38:56 +00:00
}
2020-04-16 19:41:37 +00:00
/// <summary>
/// Returns the list of all currencies currently available on the portal
/// </summary>
/// <short>Get currency list</short>
/// <category>Common</category>
/// <returns>
/// List of available currencies
/// </returns>
2022-05-31 14:01:58 +00:00
[HttpGet(@"settings/currency")]
2021-03-09 15:37:16 +00:00
public IEnumerable < CurrencyInfoDto > GetAvaliableCurrency ( )
2020-04-16 19:41:37 +00:00
{
2021-03-23 15:41:56 +00:00
return _currencyProvider . GetAll ( ) . ConvertAll ( item = > _mapper . Map < CurrencyInfoDto > ( item ) ) ;
2020-04-16 19:41:37 +00:00
}
/// <summary>
/// Returns the result of convertation from one currency to another
/// </summary>
/// <param name="amount">Amount to convert</param>
/// <param name="fromcurrency">Old currency key</param>
/// <param name="tocurrency">New currency key</param>
/// <short>Get the result of convertation</short>
/// <category>Common</category>
/// <returns>
/// Decimal result of convertation
/// </returns>
2022-05-31 14:01:58 +00:00
[HttpGet(@"settings/currency/convert")]
2020-04-16 19:41:37 +00:00
public Decimal ConvertAmount ( Decimal amount , String fromcurrency , String tocurrency )
{
2021-03-23 15:41:56 +00:00
return _currencyProvider . MoneyConvert ( amount , fromcurrency , tocurrency ) ;
2020-04-16 19:41:37 +00:00
}
/// <summary>
/// Returns the summary table with rates for selected currency
/// </summary>
/// <param name="currency" remark="Allowed values: EUR, RUB etc. You can get the whole list of available currencies by api">Currency (Abbreviation)</param>
/// <short>Get the summary table</short>
/// <category>Common</category>
/// <returns>
/// Dictionary of currencies and rates
/// </returns>
/// <exception cref="ArgumentException"></exception>
2022-05-31 14:01:58 +00:00
[HttpGet(@"settings/currency/summarytable")]
2021-03-09 15:37:16 +00:00
public IEnumerable < CurrencyRateInfoDto > GetSummaryTable ( String currency )
2020-04-16 19:41:37 +00:00
{
2021-03-09 15:37:16 +00:00
var result = new List < CurrencyRateInfoDto > ( ) ;
2020-04-16 19:41:37 +00:00
if ( string . IsNullOrEmpty ( currency ) )
{
throw new ArgumentException ( ) ;
}
2021-03-23 15:41:56 +00:00
var cur = _currencyProvider . Get ( currency . ToUpper ( ) ) ;
2021-03-19 16:56:26 +00:00
2020-04-16 19:41:37 +00:00
if ( cur = = null ) throw new ArgumentException ( ) ;
2021-06-04 16:27:44 +00:00
var table = _currencyProvider . MoneyConvert ( cur ) . ToList ( ) ;
2021-03-19 16:56:26 +00:00
2021-06-04 16:27:44 +00:00
foreach ( var row in table )
{
var currencyInfoDto = _mapper . Map < CurrencyRateInfoDto > ( row . Key ) ;
currencyInfoDto . Rate = row . Value ;
result . Add ( currencyInfoDto ) ;
}
2021-03-19 16:56:26 +00:00
2020-04-16 19:41:37 +00:00
return result ;
}
/// <summary>
///
/// </summary>
/// <param name="changeContactStatusGroupAuto" remark="true, false or null">Change contact status group auto</param>
/// <short></short>
/// <category>Contacts</category>
/// <returns>
/// ChangeContactStatusGroupAuto setting value (true, false or null)
/// </returns>
/// <exception cref="SecurityException"></exception>
2022-05-31 14:01:58 +00:00
[HttpPut(@"contact/status/settings")]
2020-04-16 19:41:37 +00:00
public Boolean ? UpdateCRMContactStatusSettings ( Boolean ? changeContactStatusGroupAuto )
2021-03-02 16:29:07 +00:00
{
2021-05-05 14:09:05 +00:00
var tenantSettings = _settingsManager . Load < CrmSettings > ( ) ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
tenantSettings . ChangeContactStatusGroupAuto = changeContactStatusGroupAuto ;
2020-04-18 17:49:09 +00:00
2021-05-05 14:09:05 +00:00
_settingsManager . Save < CrmSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . ContactTemperatureLevelSettingsUpdated ) ;
2020-04-16 19:41:37 +00:00
return changeContactStatusGroupAuto ;
}
/// <summary>
///
/// </summary>
/// <param name="writeMailToHistoryAuto" remark="true or false">Write mail to history auto</param>
/// <short></short>
/// <category>Contacts</category>
/// <returns>
/// WriteMailToHistoryAuto setting value (true or false)
/// </returns>
/// <exception cref="SecurityException"></exception>
2022-05-31 14:01:58 +00:00
[HttpPut(@"contact/mailtohistory/settings")]
2020-04-16 19:41:37 +00:00
public Boolean UpdateCRMWriteMailToHistorySettings ( Boolean writeMailToHistoryAuto )
{
2021-05-05 14:09:05 +00:00
var tenantSettings = _settingsManager . Load < CrmSettings > ( ) ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
tenantSettings . WriteMailToHistoryAuto = writeMailToHistoryAuto ;
2020-04-18 17:49:09 +00:00
2021-05-05 14:09:05 +00:00
_settingsManager . Save < CrmSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
//MessageService.Send( MessageAction.ContactTemperatureLevelSettingsUpdated);
return writeMailToHistoryAuto ;
}
/// <summary>
///
/// </summary>
/// <param name="addTagToContactGroupAuto" remark="true, false or null">add tag to contact group auto</param>
/// <short></short>
/// <category>Contacts</category>
/// <returns>
/// AddTagToContactGroupAuto setting value (true, false or null)
/// </returns>
/// <exception cref="SecurityException"></exception>
2022-05-31 14:01:58 +00:00
[HttpPut(@"contact/tag/settings")]
2020-04-16 19:41:37 +00:00
public Boolean ? UpdateCRMContactTagSettings ( Boolean ? addTagToContactGroupAuto )
{
2021-05-05 14:09:05 +00:00
var tenantSettings = _settingsManager . Load < CrmSettings > ( ) ;
2020-04-16 19:41:37 +00:00
tenantSettings . AddTagToContactGroupAuto = addTagToContactGroupAuto ;
2020-04-18 17:49:09 +00:00
2021-05-05 14:09:05 +00:00
_settingsManager . Save < CrmSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . ContactsTagSettingsUpdated ) ;
2020-04-16 19:41:37 +00:00
return addTagToContactGroupAuto ;
}
/// <summary>
/// Set IsConfiguredPortal tenant setting and website contact form key specified in the request
/// </summary>
/// <short>Set tenant settings</short>
/// <category>Common</category>
/// <returns>
/// IsConfiguredPortal setting value (true or false)
/// </returns>
2022-05-31 14:01:58 +00:00
[HttpPut(@"settings")]
2020-04-16 19:41:37 +00:00
public Boolean SetIsPortalConfigured ( Boolean ? configured , Guid ? webFormKey )
{
2021-03-19 16:56:26 +00:00
if ( ! _crmSecurity . IsAdmin ) throw _crmSecurity . CreateSecurityException ( ) ;
2020-04-18 17:49:09 +00:00
2021-05-05 14:09:05 +00:00
var tenantSettings = _settingsManager . Load < CrmSettings > ( ) ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
tenantSettings . IsConfiguredPortal = configured ? ? true ;
tenantSettings . WebFormKey = webFormKey ? ? Guid . NewGuid ( ) ;
2020-04-18 17:49:09 +00:00
2021-05-05 14:09:05 +00:00
_settingsManager . Save < CrmSettings > ( tenantSettings ) ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
return tenantSettings . IsConfiguredPortal ;
}
/// <summary>
/// Save organisation company name
/// </summary>
/// <param name="companyName">Organisation company name</param>
/// <short>Save organisation company name</short>
/// <category>Organisation</category>
/// <returns>Organisation company name</returns>
/// <exception cref="SecurityException"></exception>
2022-05-31 14:01:58 +00:00
[HttpPut(@"settings/organisation/base")]
2020-04-16 19:41:37 +00:00
public String UpdateOrganisationSettingsCompanyName ( String companyName )
{
2021-03-19 16:56:26 +00:00
if ( ! _crmSecurity . IsAdmin ) throw _crmSecurity . CreateSecurityException ( ) ;
2020-04-18 17:49:09 +00:00
2021-05-05 14:09:05 +00:00
var tenantSettings = _settingsManager . Load < CrmSettings > ( ) ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
if ( tenantSettings . InvoiceSetting = = null )
{
2021-03-23 15:41:56 +00:00
tenantSettings . InvoiceSetting = _invoiceSetting . DefaultSettings ;
2020-04-16 19:41:37 +00:00
}
tenantSettings . InvoiceSetting . CompanyName = companyName ;
2021-05-05 14:09:05 +00:00
_settingsManager . Save < CrmSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . OrganizationProfileUpdatedCompanyName , companyName ) ;
2020-04-16 19:41:37 +00:00
return companyName ;
}
/// <summary>
/// Save organisation company address
/// </summary>
/// <param name="street">Organisation company street/building/apartment address</param>
/// <param name="city">City</param>
/// <param name="state">State</param>
/// <param name="zip">Zip</param>
/// <param name="country">Country</param>
/// <short>Save organisation company address</short>
/// <category>Organisation</category>
/// <returns>Returns a JSON object with the organization company address details</returns>
/// <exception cref="SecurityException"></exception>
2022-05-31 14:01:58 +00:00
[HttpPut(@"settings/organisation/address")]
2020-04-16 19:41:37 +00:00
public String UpdateOrganisationSettingsCompanyAddress ( String street , String city , String state , String zip , String country )
{
2021-03-19 16:56:26 +00:00
if ( ! _crmSecurity . IsAdmin ) throw _crmSecurity . CreateSecurityException ( ) ;
2020-04-16 19:41:37 +00:00
2021-05-05 14:09:05 +00:00
var tenantSettings = _settingsManager . Load < CrmSettings > ( ) ;
2020-04-16 19:41:37 +00:00
if ( tenantSettings . InvoiceSetting = = null )
{
2021-03-23 15:41:56 +00:00
tenantSettings . InvoiceSetting = _invoiceSetting . DefaultSettings ;
2020-04-16 19:41:37 +00:00
}
2021-05-28 15:18:55 +00:00
var companyAddress = JsonSerializer . Serialize ( new
2021-03-02 16:29:07 +00:00
{
2022-01-17 08:22:52 +00:00
type = nameof ( AddressCategory . Billing ) ,
2021-03-02 16:29:07 +00:00
street ,
city ,
state ,
zip ,
country
} ) ;
2020-04-16 19:41:37 +00:00
tenantSettings . InvoiceSetting . CompanyAddress = companyAddress ;
2021-05-05 14:09:05 +00:00
_settingsManager . Save < CrmSettings > ( tenantSettings ) ;
2020-04-16 19:41:37 +00:00
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . OrganizationProfileUpdatedAddress ) ;
2020-04-16 19:41:37 +00:00
return companyAddress ;
}
/// <summary>
/// Save organisation logo
/// </summary>
/// <param name="reset">Reset organisation logo</param>
/// <short>Save organisation logo</short>
/// <category>Organisation</category>
/// <returns>Organisation logo ID</returns>
/// <exception cref="SecurityException"></exception>
/// <exception cref="Exception"></exception>
2022-05-31 14:01:58 +00:00
[HttpPut(@"settings/organisation/logo")]
2022-02-16 12:57:37 +00:00
public Task < Int32 > UpdateOrganisationSettingsLogoAsync ( bool reset )
2020-04-16 19:41:37 +00:00
{
2021-03-19 16:56:26 +00:00
if ( ! _crmSecurity . IsAdmin ) throw _crmSecurity . CreateSecurityException ( ) ;
2020-04-18 17:49:09 +00:00
2022-02-16 12:57:37 +00:00
return InternalUpdateOrganisationSettingsLogoAsync ( reset ) ;
}
private async Task < Int32 > InternalUpdateOrganisationSettingsLogoAsync ( bool reset )
{
2020-04-16 19:41:37 +00:00
int companyLogoID ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
if ( ! reset )
{
2022-02-10 18:25:40 +00:00
companyLogoID = await _organisationLogoManager . TryUploadOrganisationLogoFromTmpAsync ( _daoFactory ) ;
2020-04-16 19:41:37 +00:00
if ( companyLogoID = = 0 )
{
throw new Exception ( "Downloaded image not found" ) ;
}
}
else
{
companyLogoID = 0 ;
}
2021-05-05 14:09:05 +00:00
var tenantSettings = _settingsManager . Load < CrmSettings > ( ) ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
if ( tenantSettings . InvoiceSetting = = null )
{
2021-03-23 15:41:56 +00:00
tenantSettings . InvoiceSetting = _invoiceSetting . DefaultSettings ;
2020-04-16 19:41:37 +00:00
}
tenantSettings . InvoiceSetting . CompanyLogoID = companyLogoID ;
2021-05-05 14:09:05 +00:00
_settingsManager . Save < CrmSettings > ( tenantSettings ) ;
2020-04-18 17:49:09 +00:00
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . OrganizationProfileUpdatedInvoiceLogo ) ;
2020-04-16 19:41:37 +00:00
return companyLogoID ;
}
/// <summary>
/// Get organisation logo in base64 format (if 'id' is 0 then take current logo)
/// </summary>
/// <param name="id">organisation logo id</param>
/// <short>Get organisation logo</short>
/// <category>Organisation</category>
/// <returns>Organisation logo content in base64</returns>
/// <exception cref="Exception"></exception>
2022-05-31 14:01:58 +00:00
[HttpGet(@"settings/organisation/logo")]
2020-04-16 19:41:37 +00:00
public String GetOrganisationSettingsLogo ( int id )
{
if ( id ! = 0 )
{
2021-03-23 15:41:56 +00:00
return _organisationLogoManager . GetOrganisationLogoBase64 ( id ) ;
2020-04-16 19:41:37 +00:00
}
else
{
2021-05-05 14:09:05 +00:00
var tenantSettings = _settingsManager . Load < CrmSettings > ( ) ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
if ( tenantSettings . InvoiceSetting = = null )
{
return string . Empty ;
}
2021-03-23 15:41:56 +00:00
return _organisationLogoManager . GetOrganisationLogoBase64 ( tenantSettings . InvoiceSetting . CompanyLogoID ) ;
2020-04-16 19:41:37 +00:00
}
}
/// <summary>
/// Change Website Contact Form key
/// </summary>
/// <short>Change web form key</short>
/// <category>Common</category>
/// <returns>Web form key</returns>
/// <exception cref="SecurityException"></exception>
2022-05-31 14:01:58 +00:00
[HttpPut(@"settings/webformkey/change")]
2020-04-16 19:41:37 +00:00
public string ChangeWebToLeadFormKey ( )
{
2021-03-19 16:56:26 +00:00
if ( ! _crmSecurity . IsAdmin ) throw _crmSecurity . CreateSecurityException ( ) ;
2020-04-16 19:41:37 +00:00
2021-05-05 14:09:05 +00:00
var tenantSettings = _settingsManager . Load < CrmSettings > ( ) ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
tenantSettings . WebFormKey = Guid . NewGuid ( ) ;
2021-05-05 14:09:05 +00:00
_settingsManager . Save < CrmSettings > ( tenantSettings ) ;
2020-04-18 17:49:09 +00:00
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . WebsiteContactFormUpdatedKey ) ;
2020-04-16 19:41:37 +00:00
return tenantSettings . WebFormKey . ToString ( ) ;
}
/// <summary>
/// Change default CRM currency
/// </summary>
/// <param name="currency" remark="Allowed values: EUR, RUB etc. You can get the whole list of available currencies by api">Currency (Abbreviation)</param>
/// <short>Change currency</short>
/// <category>Common</category>
/// <returns>currency</returns>
/// <exception cref="SecurityException"></exception>
/// <exception cref="ArgumentException"></exception>
2022-05-31 14:01:58 +00:00
[HttpPut(@"settings/currency")]
2021-03-09 15:37:16 +00:00
public CurrencyInfoDto UpdateCRMCurrency ( String currency )
2020-04-16 19:41:37 +00:00
{
2021-03-19 16:56:26 +00:00
if ( ! _crmSecurity . IsAdmin ) throw _crmSecurity . CreateSecurityException ( ) ;
2020-04-16 19:41:37 +00:00
if ( string . IsNullOrEmpty ( currency ) )
{
throw new ArgumentException ( ) ;
}
currency = currency . ToUpper ( ) ;
2021-03-23 15:41:56 +00:00
var cur = _currencyProvider . Get ( currency ) ;
2020-04-16 19:41:37 +00:00
if ( cur = = null ) throw new ArgumentException ( ) ;
2021-03-23 15:41:56 +00:00
_global . SaveDefaultCurrencySettings ( cur ) ;
_messageService . Send ( MessageAction . CrmDefaultCurrencyUpdated ) ;
2020-04-16 19:41:37 +00:00
2021-03-19 16:56:26 +00:00
return _mapper . Map < CurrencyInfoDto > ( cur ) ;
2020-04-16 19:41:37 +00:00
}
/// <visible>false</visible>
2022-05-31 14:01:58 +00:00
[HttpPost(@"{entityType:regex(contact|opportunity|case|task)}/import/start")]
2021-06-28 09:42:42 +00:00
public string StartImportFromCSV (
[FromRoute] string entityType ,
[FromBody] StartImportFromCSVRequestDto inDto )
2020-04-16 19:41:37 +00:00
{
2021-06-28 09:42:42 +00:00
var csvFileURI = inDto . CsvFileURI ;
var jsonSettings = inDto . JsonSettings ;
2020-04-16 19:41:37 +00:00
EntityType entityTypeObj ;
if ( string . IsNullOrEmpty ( entityType ) | | string . IsNullOrEmpty ( csvFileURI ) | | string . IsNullOrEmpty ( jsonSettings ) ) throw new ArgumentException ( ) ;
switch ( entityType . ToLower ( ) )
{
case "contact" :
entityTypeObj = EntityType . Contact ;
break ;
case "opportunity" :
entityTypeObj = EntityType . Opportunity ;
break ;
case "case" :
entityTypeObj = EntityType . Case ;
break ;
case "task" :
entityTypeObj = EntityType . Task ;
break ;
default :
throw new ArgumentException ( ) ;
}
2021-03-23 15:41:56 +00:00
_importFromCSVManager . StartImport ( entityTypeObj , csvFileURI , jsonSettings ) ;
2021-03-02 16:29:07 +00:00
2020-04-16 19:41:37 +00:00
return "" ;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
}
/// <visible>false</visible>
2022-05-31 14:01:58 +00:00
[HttpGet(@"{entityType:regex(contact|opportunity|case|task)}/import/status")]
2020-04-16 19:41:37 +00:00
public IProgressItem GetImportFromCSVStatus ( string entityType )
{
EntityType entityTypeObj ;
if ( string . IsNullOrEmpty ( entityType ) ) throw new ArgumentException ( ) ;
switch ( entityType . ToLower ( ) )
{
case "contact" :
entityTypeObj = EntityType . Contact ;
break ;
case "opportunity" :
entityTypeObj = EntityType . Opportunity ;
break ;
case "case" :
entityTypeObj = EntityType . Case ;
break ;
case "task" :
entityTypeObj = EntityType . Task ;
break ;
default :
throw new ArgumentException ( ) ;
}
2021-03-23 15:41:56 +00:00
return _importFromCSV . GetStatus ( entityTypeObj ) ;
2020-04-16 19:41:37 +00:00
}
2021-03-13 18:00:08 +00:00
/// <visible>false</visible>
2022-05-31 14:01:58 +00:00
[HttpGet(@"import/samplerow")]
2022-02-16 12:57:37 +00:00
public Task < String > GetImportFromCSVSampleRowAsync ( string csvFileURI , int indexRow , string jsonSettings )
2021-03-13 18:00:08 +00:00
{
if ( String . IsNullOrEmpty ( csvFileURI ) | | indexRow < 0 ) throw new ArgumentException ( ) ;
2022-02-16 12:57:37 +00:00
return InternalGetImportFromCSVSampleRowAsync ( csvFileURI , indexRow , jsonSettings ) ;
}
private async Task < String > InternalGetImportFromCSVSampleRowAsync ( string csvFileURI , int indexRow , string jsonSettings )
{
2022-02-10 18:25:40 +00:00
if ( ! await _global . GetStore ( ) . IsFileAsync ( "temp" , csvFileURI ) ) throw new ArgumentException ( ) ;
2021-03-13 18:00:08 +00:00
2022-02-10 18:25:40 +00:00
var CSVFileStream = await _global . GetStore ( ) . GetReadStreamAsync ( "temp" , csvFileURI ) ;
2021-03-13 18:00:08 +00:00
2021-03-23 15:41:56 +00:00
return _importFromCSV . GetRow ( CSVFileStream , indexRow , jsonSettings ) ;
2021-03-13 18:00:08 +00:00
}
/// <visible>false</visible>
2022-05-31 14:01:58 +00:00
[HttpPost(@"import/uploadfake")]
2022-02-10 18:25:40 +00:00
public Task < FileUploadResult > ProcessUploadFakeAsync ( [ FromBody ] ProcessUploadFakeRequestDto inDto )
2021-03-13 18:00:08 +00:00
{
2021-06-28 09:42:42 +00:00
var csvFileURI = inDto . CsvFileURI ;
var jsonSettings = inDto . JsonSettings ;
2022-02-10 18:25:40 +00:00
return _importFromCSVManager . ProcessUploadFakeAsync ( csvFileURI , jsonSettings ) ;
2021-03-13 18:00:08 +00:00
}
/// <visible>false</visible>
2022-05-31 14:01:58 +00:00
[HttpGet(@"export/status")]
2021-03-13 18:00:08 +00:00
public IProgressItem GetExportStatus ( )
{
2021-03-19 16:56:26 +00:00
if ( ! _crmSecurity . IsAdmin ) throw _crmSecurity . CreateSecurityException ( ) ;
2021-03-13 18:00:08 +00:00
2021-03-23 15:41:56 +00:00
return _exportToCsv . GetStatus ( false ) ;
2021-03-13 18:00:08 +00:00
}
/// <visible>false</visible>
2022-05-31 14:01:58 +00:00
[HttpPut(@"export/cancel")]
2021-03-13 18:00:08 +00:00
public IProgressItem CancelExport ( )
{
2021-03-19 16:56:26 +00:00
if ( ! _crmSecurity . IsAdmin ) throw _crmSecurity . CreateSecurityException ( ) ;
2021-03-13 18:00:08 +00:00
2021-03-23 15:41:56 +00:00
_exportToCsv . Cancel ( false ) ;
2021-03-13 18:00:08 +00:00
2021-03-23 15:41:56 +00:00
return _exportToCsv . GetStatus ( false ) ;
2021-03-13 18:00:08 +00:00
}
/// <visible>false</visible>
2022-05-31 14:01:58 +00:00
[HttpPost(@"export/start")]
2021-03-13 18:00:08 +00:00
public IProgressItem StartExport ( )
{
2021-03-19 16:56:26 +00:00
if ( ! _crmSecurity . IsAdmin ) throw _crmSecurity . CreateSecurityException ( ) ;
2021-03-13 18:00:08 +00:00
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . CrmAllDataExported ) ;
2021-03-13 18:00:08 +00:00
2021-03-23 15:41:56 +00:00
return _exportToCsv . Start ( null , CRMSettingResource . Export + ".zip" ) ;
2021-03-13 18:00:08 +00:00
}
/// <visible>false</visible>
2022-05-31 14:01:58 +00:00
[HttpGet(@"export/partial/status")]
2021-03-13 18:00:08 +00:00
public IProgressItem GetPartialExportStatus ( )
{
2021-03-23 15:41:56 +00:00
return _exportToCsv . GetStatus ( true ) ;
2021-03-13 18:00:08 +00:00
}
/// <visible>false</visible>
2022-05-31 14:01:58 +00:00
[HttpPut(@"export/partial/cancel")]
2021-03-13 18:00:08 +00:00
public IProgressItem CancelPartialExport ( )
{
2021-03-23 15:41:56 +00:00
_exportToCsv . Cancel ( true ) ;
2021-03-13 18:00:08 +00:00
2021-03-23 15:41:56 +00:00
return _exportToCsv . GetStatus ( true ) ;
2021-03-13 18:00:08 +00:00
}
/// <visible>false</visible>
2022-05-31 14:01:58 +00:00
[HttpPost(@"export/partial/{entityType:regex(contact|opportunity|case|task|invoiceitem)}/start")]
2021-06-28 09:42:42 +00:00
public IProgressItem StartPartialExport ( [ FromRoute ] string entityType , [ FromBody ] string base64FilterString )
2021-03-13 18:00:08 +00:00
{
if ( string . IsNullOrEmpty ( base64FilterString ) ) throw new ArgumentException ( ) ;
FilterObject filterObject ;
String fileName ;
switch ( entityType . ToLower ( ) )
{
case "contact" :
filterObject = new ContactFilterObject ( base64FilterString ) ;
fileName = CRMContactResource . Contacts + ".csv" ;
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . ContactsExportedToCsv ) ;
2021-03-13 18:00:08 +00:00
break ;
case "opportunity" :
filterObject = new DealFilterObject ( base64FilterString ) ;
fileName = CRMCommonResource . DealModuleName + ".csv" ;
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . OpportunitiesExportedToCsv ) ;
2021-03-13 18:00:08 +00:00
break ;
case "case" :
filterObject = new CasesFilterObject ( base64FilterString ) ;
fileName = CRMCommonResource . CasesModuleName + ".csv" ;
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . CasesExportedToCsv ) ;
2021-03-13 18:00:08 +00:00
break ;
case "task" :
filterObject = new TaskFilterObject ( base64FilterString ) ;
fileName = CRMCommonResource . TaskModuleName + ".csv" ;
2021-03-23 15:41:56 +00:00
_messageService . Send ( MessageAction . CrmTasksExportedToCsv ) ;
2021-03-13 18:00:08 +00:00
break ;
case "invoiceitem" :
fileName = CRMCommonResource . ProductsAndServices + ".csv" ;
filterObject = new InvoiceItemFilterObject ( base64FilterString ) ;
break ;
default :
throw new ArgumentException ( ) ;
}
2021-03-23 15:41:56 +00:00
return _exportToCsv . Start ( filterObject , fileName ) ;
2021-03-13 18:00:08 +00:00
}
2020-04-16 19:41:37 +00:00
}
}