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-10 15:38:56 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
using ASC.Api.Collections;
|
|
|
|
using ASC.Api.Core;
|
2021-03-10 15:38:56 +00:00
|
|
|
using ASC.Api.CRM;
|
2021-03-13 18:00:08 +00:00
|
|
|
using ASC.Common.Threading.Progress;
|
2020-04-16 19:41:37 +00:00
|
|
|
using ASC.Common.Web;
|
2021-03-10 15:38:56 +00:00
|
|
|
using ASC.Core;
|
|
|
|
using ASC.Core.Users;
|
|
|
|
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;
|
|
|
|
using ASC.CRM.Core.Enums;
|
|
|
|
using ASC.CRM.Resources;
|
|
|
|
using ASC.MessagingSystem;
|
2020-04-18 17:49:09 +00:00
|
|
|
using ASC.Web.Api.Models;
|
2020-04-16 19:41:37 +00:00
|
|
|
using ASC.Web.Api.Routing;
|
2020-04-18 17:49:09 +00:00
|
|
|
using ASC.Web.CRM.Classes;
|
2021-03-10 15:38:56 +00:00
|
|
|
using ASC.Web.CRM.Services.NotifyService;
|
2020-04-16 19:41:37 +00:00
|
|
|
using ASC.Web.Studio.Core;
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
using Autofac;
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2021-03-17 11:50:13 +00:00
|
|
|
using AutoMapper;
|
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2021-03-05 20:06:49 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
using Contact = ASC.CRM.Core.Entities.Contact;
|
|
|
|
|
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 ContactsController : BaseApiController
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
private readonly MailSender _mailSender;
|
|
|
|
private readonly FileSizeComment _fileSizeComment;
|
|
|
|
private readonly ContactPhotoManager _contactPhotoManager;
|
|
|
|
private readonly EmployeeWraperHelper _employeeWraperHelper;
|
|
|
|
private readonly UserFormatter _userFormatter;
|
|
|
|
private readonly SetupInfo _setupInfo;
|
|
|
|
private readonly SecurityContext _securityContext;
|
|
|
|
private readonly NotifyClient _notifyClient;
|
|
|
|
private readonly ApiContext _apiContext;
|
|
|
|
private readonly MessageService _messageService;
|
|
|
|
private readonly MessageTarget _messageTarget;
|
|
|
|
|
2021-05-05 14:09:05 +00:00
|
|
|
public ContactsController(CrmSecurity crmSecurity,
|
2021-03-10 15:38:56 +00:00
|
|
|
DaoFactory daoFactory,
|
|
|
|
ApiContext apiContext,
|
|
|
|
MessageTarget messageTarget,
|
|
|
|
MessageService messageService,
|
|
|
|
NotifyClient notifyClient,
|
|
|
|
SecurityContext securityContext,
|
|
|
|
SetupInfo setupInfo,
|
|
|
|
UserFormatter userFormatter,
|
|
|
|
EmployeeWraperHelper employeeWraperHelper,
|
|
|
|
ContactPhotoManager contactPhotoManager,
|
|
|
|
FileSizeComment fileSizeComment,
|
2021-03-17 11:50:13 +00:00
|
|
|
MailSender mailSender,
|
|
|
|
IMapper mapper)
|
2021-03-19 16:56:26 +00:00
|
|
|
: base(daoFactory, crmSecurity, mapper)
|
2021-03-10 15:38:56 +00:00
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
_apiContext = apiContext;
|
|
|
|
_messageTarget = messageTarget;
|
|
|
|
_messageService = messageService;
|
|
|
|
_notifyClient = notifyClient;
|
|
|
|
_securityContext = securityContext;
|
|
|
|
_setupInfo = setupInfo;
|
|
|
|
_userFormatter = userFormatter;
|
|
|
|
_employeeWraperHelper = employeeWraperHelper;
|
|
|
|
_contactPhotoManager = contactPhotoManager;
|
|
|
|
_fileSizeComment = fileSizeComment;
|
|
|
|
_mailSender = mailSender;
|
2021-03-17 11:50:13 +00:00
|
|
|
_mapper = mapper;
|
2021-03-10 15:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the detailed information about the contact with the ID specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="contactid">Contact ID</param>
|
|
|
|
/// <returns>Contact</returns>
|
|
|
|
/// <short>Get contact by ID</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
2021-03-02 16:29:07 +00:00
|
|
|
[Read(@"contact/{contactid:int}")]
|
2021-03-19 16:56:26 +00:00
|
|
|
public ContactDto GetContactByID(int contactid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (contactid <= 0) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contact = _daoFactory.GetContactDao().GetByID(contactid);
|
|
|
|
if (contact == null || !_crmSecurity.CanAccessTo(contact)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mapper.Map<ContactDto>(contact);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactDto> GetContactsByID(IEnumerable<int> contactid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var contacts = _daoFactory.GetContactDao().GetContacts(contactid.ToArray()).Where(r => r != null && _crmSecurity.CanAccessTo(r)).ToList();
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mapper.Map<List<Contact>, List<ContactDto>>(contacts);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the contact list for the project with the ID specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <short>
|
|
|
|
/// Get contacts by project ID
|
|
|
|
/// </short>
|
|
|
|
/// <param name="projectid">Project ID</param>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
///<exception cref="ArgumentException"></exception>
|
|
|
|
[Read(@"contact/project/{projectid:int}")]
|
2021-03-19 16:56:26 +00:00
|
|
|
public IEnumerable<ContactDto> GetContactsByProjectID(int projectid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (projectid <= 0) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contacts = _daoFactory.GetContactDao().GetContactsByProjectID(projectid);
|
|
|
|
|
|
|
|
return _mapper.Map<List<Contact>, List<ContactDto>>(contacts.ToList());
|
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
///// <summary>
|
|
|
|
///// Links the selected contact to the project with the ID specified in the request
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="contactid">Contact ID</param>
|
|
|
|
///// <param name="projectid">Project ID</param>
|
|
|
|
///// <category>Contacts</category>
|
|
|
|
///// <short>Link contact with project</short>
|
|
|
|
///// <exception cref="ArgumentException"></exception>
|
|
|
|
///// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
///// <returns>Contact Info</returns>
|
|
|
|
//[Create(@"contact/{contactid:int}/project/{projectid:int}")]
|
2021-03-09 15:37:16 +00:00
|
|
|
//public ContactDto SetRelativeContactToProject(int contactid, int projectid)
|
2020-04-18 17:49:09 +00:00
|
|
|
//{
|
|
|
|
// if (contactid <= 0 || projectid <= 0) throw new ArgumentException();
|
|
|
|
|
|
|
|
// var contact = DaoFactory.GetContactDao().GetByID(contactid);
|
|
|
|
// if (contact == null || !CRMSecurity.CanAccessTo(contact)) throw new ItemNotFoundException();
|
|
|
|
|
|
|
|
// var project = ProjectsDaoFactory.ProjectDao.GetById(projectid);
|
|
|
|
// if (project == null) throw new ItemNotFoundException();
|
|
|
|
|
|
|
|
// using (var scope = DIHelper.Resolve())
|
|
|
|
// {
|
|
|
|
// if (!scope.Resolve<ProjectSecurity>().CanLinkContact(project)) throw CRMSecurity.CreateSecurityException();
|
|
|
|
// }
|
|
|
|
|
2021-03-02 16:29:07 +00:00
|
|
|
// DaoFactory.GetContactDao().SetRelativeContactProject(new List<int> { contactid }, projectid);
|
2020-04-18 17:49:09 +00:00
|
|
|
|
|
|
|
// var messageAction = contact is Company ? MessageAction.ProjectLinkedCompany : MessageAction.ProjectLinkedPerson;
|
2021-03-02 16:29:07 +00:00
|
|
|
// MessageService.Send(messageAction, MessageTarget.Create(contact.ID), project.Title, contact.GetTitle());
|
2020-04-18 17:49:09 +00:00
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
// return ToContactDto(contact);
|
2020-04-18 17:49:09 +00:00
|
|
|
//}
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// Links the selected contacts to the project with the ID specified in the request
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="contactid">Contact IDs array</param>
|
|
|
|
///// <param name="projectid">Project ID</param>
|
|
|
|
///// <category>Contacts</category>
|
|
|
|
///// <short>Link contact list with project</short>
|
|
|
|
///// <exception cref="ArgumentException"></exception>
|
|
|
|
///// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
///// <returns>
|
|
|
|
///// Contact list
|
|
|
|
///// </returns>
|
|
|
|
//[Create(@"contact/project/{projectid:int}")]
|
2021-03-09 15:37:16 +00:00
|
|
|
//public IEnumerable<ContactDto> SetRelativeContactListToProject(IEnumerable<int> contactid, int projectid)
|
2020-04-18 17:49:09 +00:00
|
|
|
//{
|
|
|
|
// if (contactid == null) throw new ArgumentException();
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// var contactIds = contactid.ToList();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// if (!contactIds.Any() || projectid <= 0) throw new ArgumentException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// var project = ProjectsDaoFactory.ProjectDao.GetById(projectid);
|
|
|
|
// if (project == null) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// using (var scope = DIHelper.Resolve())
|
|
|
|
// {
|
|
|
|
// if (!scope.Resolve<ProjectSecurity>().CanLinkContact(project))
|
|
|
|
// throw CRMSecurity.CreateSecurityException();
|
|
|
|
// }
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// var contacts = DaoFactory.GetContactDao().GetContacts(contactIds.ToArray()).Where(CRMSecurity.CanAccessTo).ToList();
|
|
|
|
// contactIds = contacts.Select(c => c.ID).ToList();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// DaoFactory.GetContactDao().SetRelativeContactProject(contactIds, projectid);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-02 16:29:07 +00:00
|
|
|
// MessageService.Send(MessageAction.ProjectLinkedContacts, MessageTarget.Create(contactIds), project.Title, contacts.Select(x => x.GetTitle()));
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
// return contacts.ConvertAll(ToContactDto);
|
2020-04-18 17:49:09 +00:00
|
|
|
//}
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
///// <summary>
|
|
|
|
///// Removes the link with the selected project from the contact with the ID specified in the request
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="contactid">Contact ID</param>
|
|
|
|
///// <param name="projectid">Project ID</param>
|
|
|
|
///// <category>Contacts</category>
|
|
|
|
///// <short>Remove contact from project</short>
|
|
|
|
///// <returns>
|
|
|
|
///// Contact info
|
|
|
|
///// </returns>
|
|
|
|
//[Delete(@"contact/{contactid:int}/project/{projectid:int}")]
|
2021-03-09 15:37:16 +00:00
|
|
|
//public ContactBaseDto RemoveRelativeContactToProject(int contactid, int projectid)
|
2020-04-18 17:49:09 +00:00
|
|
|
//{
|
|
|
|
// if (contactid <= 0 || projectid <= 0) throw new ArgumentException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// var contact = DaoFactory.GetContactDao().GetByID(contactid);
|
|
|
|
// if (contact == null || !CRMSecurity.CanAccessTo(contact)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// var project = ProjectsDaoFactory.ProjectDao.GetById(projectid);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// using (var scope = DIHelper.Resolve())
|
|
|
|
// {
|
|
|
|
// if (project == null || !scope.Resolve<ProjectSecurity>().CanLinkContact(project)) throw new ItemNotFoundException();
|
|
|
|
// }
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// DaoFactory.GetContactDao().RemoveRelativeContactProject(contactid, projectid);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
// var action = contact is Company ? MessageAction.ProjectUnlinkedCompany : MessageAction.ProjectUnlinkedPerson;
|
2021-03-02 16:29:07 +00:00
|
|
|
// MessageService.Send(action, MessageTarget.Create(contact.ID), project.Title, contact.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
// return ToContactBaseDto(contact);
|
2020-04-18 17:49:09 +00:00
|
|
|
//}
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds the selected opportunity to the contact with the ID specified in the request. The same as AddMemberToDeal
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="opportunityid">Opportunity ID</param>
|
|
|
|
/// <param name="contactid">Contact ID</param>
|
|
|
|
/// <short>Add contact opportunity</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Opportunity
|
|
|
|
/// </returns>
|
|
|
|
[Create(@"contact/{contactid:int}/opportunity/{opportunityid:int}")]
|
2021-03-24 15:55:47 +00:00
|
|
|
public OpportunityDto AddDealToContact([FromRoute] int contactid, [FromRoute] int opportunityid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if ((opportunityid <= 0) || (contactid <= 0)) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contact = _daoFactory.GetContactDao().GetByID(contactid);
|
|
|
|
if (contact == null || !_crmSecurity.CanAccessTo(contact)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var opportunity = _daoFactory.GetDealDao().GetByID(opportunityid);
|
|
|
|
if (opportunity == null || !_crmSecurity.CanAccessTo(opportunity)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetDealDao().AddMember(opportunityid, contactid);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
var messageAction = contact is Company ? MessageAction.OpportunityLinkedCompany : MessageAction.OpportunityLinkedPerson;
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(messageAction, _messageTarget.Create(contact.ID), opportunity.Title, contact.GetTitle());
|
|
|
|
|
|
|
|
return _mapper.Map<OpportunityDto>(opportunity);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Deletes the selected opportunity from the contact with the ID specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="opportunityid">Opportunity ID</param>
|
|
|
|
/// <param name="contactid">Contact ID</param>
|
|
|
|
/// <short>Delete contact opportunity</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Opportunity
|
|
|
|
/// </returns>
|
|
|
|
[Delete(@"contact/{contactid:int}/opportunity/{opportunityid:int}")]
|
2021-03-19 16:56:26 +00:00
|
|
|
public OpportunityDto DeleteDealFromContact(int contactid, int opportunityid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if ((opportunityid <= 0) || (contactid <= 0)) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contact = _daoFactory.GetContactDao().GetByID(contactid);
|
|
|
|
if (contact == null || !_crmSecurity.CanAccessTo(contact)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var opportunity = _daoFactory.GetDealDao().GetByID(opportunityid);
|
|
|
|
if (opportunity == null || !_crmSecurity.CanAccessTo(opportunity)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetDealDao().RemoveMember(opportunityid, contactid);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mapper.Map<OpportunityDto>(opportunity);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the list of all contacts in the CRM module matching the parameters specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param optional="true" name="tags">Tag</param>
|
|
|
|
/// <param optional="true" name="contactStage">Contact stage ID (warmth)</param>
|
|
|
|
/// <param optional="true" name="contactType">Contact type ID</param>
|
|
|
|
/// <param optional="true" name="contactListView" remark="Allowed values: Company, Person, WithOpportunity"></param>
|
|
|
|
/// <param optional="true" name="fromDate">Start date</param>
|
|
|
|
/// <param optional="true" name="toDate">End date</param>
|
|
|
|
/// <param optional="true" name="responsibleid">Responsible ID</param>
|
|
|
|
/// <param optional="true" name="isShared">Responsible ID</param>
|
|
|
|
/// <short>Get contact list</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
[Read(@"contact/filter")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactDto> GetContacts(
|
2021-03-19 16:56:26 +00:00
|
|
|
[FromQuery] IEnumerable<String> tags,
|
|
|
|
[FromQuery] int? contactStage,
|
|
|
|
[FromQuery] int? contactType,
|
|
|
|
[FromQuery] ContactListViewType contactListView,
|
|
|
|
[FromQuery] Guid? responsibleid,
|
|
|
|
[FromQuery] bool? isShared,
|
|
|
|
[FromQuery] ApiDateTime fromDate,
|
|
|
|
[FromQuery] ApiDateTime toDate)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
IEnumerable<ContactDto> result;
|
2020-04-16 19:41:37 +00:00
|
|
|
OrderBy contactsOrderBy;
|
|
|
|
ContactSortedByType sortBy;
|
2021-03-23 15:41:56 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var searchString = _apiContext.FilterValue;
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (ASC.CRM.Classes.EnumExtension.TryParse(_apiContext.SortBy, true, out sortBy))
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
contactsOrderBy = new OrderBy(sortBy, !_apiContext.SortDescending);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
2021-03-19 16:56:26 +00:00
|
|
|
else if (String.IsNullOrEmpty(_apiContext.SortBy))
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
contactsOrderBy = new OrderBy(ContactSortedByType.Created, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
contactsOrderBy = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var fromIndex = (int)_apiContext.StartIndex;
|
|
|
|
var count = (int)_apiContext.Count;
|
2020-04-16 19:41:37 +00:00
|
|
|
var contactStageInt = contactStage.HasValue ? contactStage.Value : -1;
|
|
|
|
var contactTypeInt = contactType.HasValue ? contactType.Value : -1;
|
|
|
|
|
|
|
|
if (contactsOrderBy != null)
|
|
|
|
{
|
2021-05-05 14:09:05 +00:00
|
|
|
|
|
|
|
var contacts = _daoFactory.GetContactDao().GetContacts(
|
2020-04-16 19:41:37 +00:00
|
|
|
searchString,
|
|
|
|
tags,
|
|
|
|
contactStageInt,
|
|
|
|
contactTypeInt,
|
|
|
|
contactListView,
|
|
|
|
fromDate,
|
|
|
|
toDate,
|
|
|
|
fromIndex,
|
|
|
|
count,
|
|
|
|
contactsOrderBy,
|
|
|
|
responsibleid,
|
2021-05-05 14:09:05 +00:00
|
|
|
isShared);
|
|
|
|
|
|
|
|
result = _mapper.Map<List<Contact>, List<ContactDto>>(contacts);
|
2021-06-04 14:38:42 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_apiContext.SetDataPaginated();
|
|
|
|
_apiContext.SetDataFiltered();
|
|
|
|
_apiContext.SetDataSorted();
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
result = _mapper.Map<List<Contact>, List<ContactDto>>(_daoFactory.GetContactDao().GetContacts(
|
2020-04-16 19:41:37 +00:00
|
|
|
searchString,
|
|
|
|
tags,
|
|
|
|
contactStageInt,
|
|
|
|
contactTypeInt,
|
|
|
|
contactListView,
|
|
|
|
fromDate,
|
|
|
|
toDate,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
null,
|
|
|
|
responsibleid,
|
|
|
|
isShared));
|
|
|
|
}
|
|
|
|
|
|
|
|
int totalCount;
|
|
|
|
|
|
|
|
if (result.Count() < count)
|
|
|
|
{
|
|
|
|
totalCount = fromIndex + result.Count();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
totalCount = _daoFactory.GetContactDao().GetContactsCount(
|
2020-04-16 19:41:37 +00:00
|
|
|
searchString,
|
|
|
|
tags,
|
|
|
|
contactStageInt,
|
|
|
|
contactTypeInt,
|
|
|
|
contactListView,
|
|
|
|
fromDate,
|
|
|
|
toDate,
|
|
|
|
responsibleid,
|
|
|
|
isShared);
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_apiContext.SetTotalCount(totalCount);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the list of the contacts for auto complete feature.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="term">String part of contact name, lastname or email.</param>
|
|
|
|
/// <param name="maxCount">Max result count</param>
|
|
|
|
/// <short>Search contact list</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
/// <visible>false</visible>
|
|
|
|
[Read(@"contact/simple/byEmail")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactWithTaskDto> SearchContactsByEmail(string term, int maxCount)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var result = ToSimpleListContactDto(_daoFactory.GetContactDao().SearchContactsByEmail(
|
2020-04-16 19:41:37 +00:00
|
|
|
term,
|
|
|
|
maxCount));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the list of all contacts in the CRM module matching the parameters specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param optional="true" name="tags">Tag</param>
|
|
|
|
/// <param optional="true" name="contactStage">Contact stage ID (warmth)</param>
|
|
|
|
/// <param optional="true" name="contactType">Contact type ID</param>
|
|
|
|
/// <param optional="true" name="contactListView" remark="Allowed values: Company, Person, WithOpportunity"></param>
|
|
|
|
/// <param optional="true" name="responsibleid">Responsible ID</param>
|
|
|
|
/// <param optional="true" name="isShared">Responsible ID</param>
|
|
|
|
/// <param optional="true" name="fromDate">Start date</param>
|
|
|
|
/// <param optional="true" name="toDate">End date</param>
|
|
|
|
/// <short>Get contact list</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
/// <visible>false</visible>
|
|
|
|
[Read(@"contact/simple/filter")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactWithTaskDto> GetSimpleContacts(
|
2020-04-16 19:41:37 +00:00
|
|
|
IEnumerable<string> tags,
|
|
|
|
int? contactStage,
|
|
|
|
int? contactType,
|
|
|
|
ContactListViewType contactListView,
|
|
|
|
Guid? responsibleid,
|
|
|
|
bool? isShared,
|
|
|
|
ApiDateTime fromDate,
|
|
|
|
ApiDateTime toDate)
|
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
IEnumerable<ContactWithTaskDto> result;
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
OrderBy contactsOrderBy;
|
|
|
|
|
|
|
|
ContactSortedByType sortBy;
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var searchString = _apiContext.FilterValue;
|
|
|
|
if (ASC.CRM.Classes.EnumExtension.TryParse(_apiContext.SortBy, true, out sortBy))
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
contactsOrderBy = new OrderBy(sortBy, !_apiContext.SortDescending);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
2021-03-19 16:56:26 +00:00
|
|
|
else if (String.IsNullOrEmpty(_apiContext.SortBy))
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
contactsOrderBy = new OrderBy(ContactSortedByType.DisplayName, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
contactsOrderBy = null;
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var fromIndex = (int)_apiContext.StartIndex;
|
|
|
|
var count = (int)_apiContext.Count;
|
2020-04-16 19:41:37 +00:00
|
|
|
var contactStageInt = contactStage.HasValue ? contactStage.Value : -1;
|
|
|
|
var contactTypeInt = contactType.HasValue ? contactType.Value : -1;
|
|
|
|
|
|
|
|
if (contactsOrderBy != null)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
result = ToSimpleListContactDto(_daoFactory.GetContactDao().GetContacts(
|
2020-04-16 19:41:37 +00:00
|
|
|
searchString,
|
|
|
|
tags,
|
|
|
|
contactStageInt,
|
|
|
|
contactTypeInt,
|
|
|
|
contactListView,
|
|
|
|
fromDate,
|
|
|
|
toDate,
|
|
|
|
fromIndex,
|
|
|
|
count,
|
|
|
|
contactsOrderBy,
|
|
|
|
responsibleid,
|
|
|
|
isShared));
|
2021-03-19 16:56:26 +00:00
|
|
|
_apiContext.SetDataPaginated();
|
|
|
|
_apiContext.SetDataFiltered();
|
|
|
|
_apiContext.SetDataSorted();
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
result = ToSimpleListContactDto(_daoFactory.GetContactDao().GetContacts(
|
2020-04-16 19:41:37 +00:00
|
|
|
searchString,
|
|
|
|
tags,
|
|
|
|
contactStageInt,
|
|
|
|
contactTypeInt,
|
|
|
|
contactListView,
|
|
|
|
fromDate,
|
|
|
|
toDate,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
null,
|
|
|
|
responsibleid,
|
|
|
|
isShared));
|
|
|
|
}
|
|
|
|
|
|
|
|
int totalCount;
|
|
|
|
|
|
|
|
if (result.Count() < count)
|
|
|
|
{
|
|
|
|
totalCount = fromIndex + result.Count();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
totalCount = _daoFactory.GetContactDao().GetContactsCount(
|
2020-04-16 19:41:37 +00:00
|
|
|
searchString,
|
|
|
|
tags,
|
|
|
|
contactStageInt,
|
|
|
|
contactTypeInt,
|
|
|
|
contactListView,
|
|
|
|
fromDate,
|
|
|
|
toDate,
|
|
|
|
responsibleid,
|
|
|
|
isShared);
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_apiContext.SetTotalCount(totalCount);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get the group of contacts with the IDs specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="contactids">Contact ID list</param>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <short>Get contact group</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
/// <visible>false</visible>
|
|
|
|
[Read(@"contact/mail")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactBaseWithEmailDto> GetContactsForMail(IEnumerable<int> contactids)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (contactids == null) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contacts = _daoFactory.GetContactDao().GetContacts(contactids.ToArray());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var result = contacts.Select(x => _mapper.Map<ContactBaseWithEmailDto>(x));
|
2020-04-16 19:41:37 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Deletes the list of all contacts in the CRM module matching the parameters specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param optional="true" name="tags">Tag</param>
|
|
|
|
/// <param optional="true" name="contactStage">Contact stage ID (warmth)</param>
|
|
|
|
/// <param optional="true" name="contactType">Contact type ID</param>
|
|
|
|
/// <param optional="true" name="contactListView" remark="Allowed values: Company, Person, WithOpportunity"></param>
|
|
|
|
/// <param optional="true" name="fromDate">Start date</param>
|
|
|
|
/// <param optional="true" name="toDate">End date</param>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <short>Delete the list of all contacts </short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
[Delete(@"contact/filter")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactBaseDto> DeleteBatchContacts(
|
2020-04-16 19:41:37 +00:00
|
|
|
IEnumerable<String> tags,
|
|
|
|
int? contactStage,
|
|
|
|
int? contactType,
|
|
|
|
ContactListViewType contactListView,
|
|
|
|
ApiDateTime fromDate,
|
|
|
|
ApiDateTime toDate)
|
|
|
|
{
|
|
|
|
int contactStageInt = contactStage.HasValue ? contactStage.Value : -1;
|
|
|
|
int contactTypeInt = contactType.HasValue ? contactType.Value : -1;
|
|
|
|
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contacts = _daoFactory.GetContactDao().GetContacts(
|
|
|
|
_apiContext.FilterValue,
|
2020-04-16 19:41:37 +00:00
|
|
|
tags,
|
|
|
|
contactStageInt,
|
|
|
|
contactTypeInt,
|
|
|
|
contactListView,
|
|
|
|
fromDate,
|
|
|
|
toDate,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
null);
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
contacts = _daoFactory.GetContactDao().DeleteBatchContact(contacts);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.ContactsDeleted, _messageTarget.Create(contacts.Select(c => c.ID)), contacts.Select(c => c.GetTitle()));
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return contacts.Select(x => _mapper.Map<ContactBaseDto>(x));
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the list of all the persons linked to the company with the ID specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="companyid">Company ID</param>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <short>Get company linked persons list</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>
|
|
|
|
/// Linked persons
|
|
|
|
/// </returns>
|
|
|
|
[Read(@"contact/company/{companyid:int}/person")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactDto> GetPeopleFromCompany(int companyid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (companyid <= 0) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var company = _daoFactory.GetContactDao().GetByID(companyid);
|
|
|
|
if (company == null || !_crmSecurity.CanAccessTo(company)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contacts = _daoFactory.GetContactDao().GetMembers(companyid).Where(_crmSecurity.CanAccessTo).ToList();
|
|
|
|
|
|
|
|
return _mapper.Map<List<Contact>, List<ContactDto>>(contacts);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds the selected person to the company with the ID specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param optional="true" name="companyid">Company ID</param>
|
|
|
|
/// <param optional="true" name="personid">Person ID</param>
|
|
|
|
/// <short>Add person to company</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Person
|
|
|
|
/// </returns>
|
|
|
|
[Create(@"contact/company/{companyid:int}/person")]
|
2021-06-23 19:32:56 +00:00
|
|
|
public PersonDto AddPeopleToCompany([FromRoute] int companyid, [FromBody] int personid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if ((companyid <= 0) || (personid <= 0)) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var company = _daoFactory.GetContactDao().GetByID(companyid);
|
|
|
|
var person = _daoFactory.GetContactDao().GetByID(personid);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (person == null || company == null || !_crmSecurity.CanAccessTo(person) || !_crmSecurity.CanAccessTo(company)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetContactDao().AddMember(personid, companyid);
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.CompanyLinkedPerson, _messageTarget.Create(new[] { company.ID, person.ID }), company.GetTitle(), person.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return (PersonDto)_mapper.Map<ContactDto>(person);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Deletes the selected person from the company with the ID specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param optional="true" name="companyid">Company ID</param>
|
|
|
|
/// <param optional="true" name="personid">Person ID</param>
|
|
|
|
/// <short>Delete person from company</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Person
|
|
|
|
/// </returns>
|
|
|
|
[Delete(@"contact/company/{companyid:int}/person")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public PersonDto DeletePeopleFromCompany(int companyid, int personid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if ((companyid <= 0) || (personid <= 0)) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var company = _daoFactory.GetContactDao().GetByID(companyid);
|
|
|
|
var person = _daoFactory.GetContactDao().GetByID(personid);
|
|
|
|
if (person == null || company == null || !_crmSecurity.CanAccessTo(person) || !_crmSecurity.CanAccessTo(company)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetContactDao().RemoveMember(personid);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.CompanyUnlinkedPerson, _messageTarget.Create(new[] { company.ID, person.ID }), company.GetTitle(), person.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return (PersonDto)_mapper.Map<ContactDto>(person);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates the person with the parameters (first name, last name, description, etc.) specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="firstName">First name</param>
|
|
|
|
/// <param name="lastName">Last name</param>
|
|
|
|
/// <param optional="true" name="jobTitle">Post</param>
|
|
|
|
/// <param optional="true" name="companyId">Company ID</param>
|
|
|
|
/// <param optional="true" name="about">Person description text</param>
|
|
|
|
/// <param name="shareType">Person privacy: 0 - not shared, 1 - shared for read/write, 2 - shared for read only</param>
|
|
|
|
/// <param optional="true" name="managerList">List of managers for the person</param>
|
|
|
|
/// <param optional="true" name="customFieldList">User field list</param>
|
|
|
|
/// <param optional="true" name="photo">Contact photo (upload using multipart/form-data)</param>
|
|
|
|
/// <short>Create person</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>Person</returns>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
[Create(@"contact/person")]
|
2021-06-23 19:32:56 +00:00
|
|
|
public PersonDto CreatePerson([FromBody] CreateOrUpdatePersonRequestDto intDto)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-05 20:06:49 +00:00
|
|
|
string firstName = intDto.FirstName;
|
|
|
|
string lastName = intDto.LastName;
|
|
|
|
string jobTitle = intDto.JobTitle;
|
|
|
|
int companyId = intDto.CompanyId;
|
|
|
|
string about = intDto.About;
|
|
|
|
ShareType shareType = intDto.ShareType;
|
|
|
|
IEnumerable<Guid> managerList = intDto.ManagerList;
|
|
|
|
IEnumerable<ItemKeyValuePair<int, string>> customFieldList = intDto.CustomFieldList;
|
|
|
|
IEnumerable<IFormFile> photo = intDto.Photos;
|
|
|
|
|
2021-02-24 16:50:07 +00:00
|
|
|
if (companyId > 0)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var company = _daoFactory.GetContactDao().GetByID(companyId);
|
|
|
|
if (company == null || !_crmSecurity.CanAccessTo(company)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var peopleInst = new Person
|
2021-02-24 16:50:07 +00:00
|
|
|
{
|
|
|
|
FirstName = firstName,
|
|
|
|
LastName = lastName,
|
|
|
|
JobTitle = jobTitle,
|
|
|
|
CompanyID = companyId,
|
|
|
|
About = about,
|
|
|
|
ShareType = shareType
|
|
|
|
};
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
peopleInst.ID = _daoFactory.GetContactDao().SaveContact(peopleInst);
|
|
|
|
peopleInst.CreateBy = _securityContext.CurrentAccount.ID;
|
2020-04-16 19:41:37 +00:00
|
|
|
peopleInst.CreateOn = DateTime.UtcNow;
|
|
|
|
|
|
|
|
var managerListLocal = managerList != null ? managerList.ToList() : new List<Guid>();
|
|
|
|
if (managerListLocal.Any())
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
_crmSecurity.SetAccessTo(peopleInst, managerListLocal);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (customFieldList != null)
|
|
|
|
{
|
|
|
|
foreach (var field in customFieldList)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(field.Value)) continue;
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetCustomFieldDao().SetFieldValue(EntityType.Person, peopleInst.ID, field.Key, field.Value);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var outDto = (PersonDto)_mapper.Map<ContactDto>(peopleInst);
|
2020-04-22 20:46:49 +00:00
|
|
|
|
|
|
|
var photoList = photo != null ? photo.ToList() : new List<IFormFile>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (photoList.Any())
|
|
|
|
{
|
2021-03-05 20:06:49 +00:00
|
|
|
outDto.SmallFotoUrl = ChangeContactPhoto(peopleInst.ID, photoList);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.PersonCreated, _messageTarget.Create(peopleInst.ID), peopleInst.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-05 20:06:49 +00:00
|
|
|
return outDto;
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Changes the photo for the contact with the ID specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="contactid">Contact ID</param>
|
|
|
|
/// <param name="photo">Contact photo (upload using multipart/form-data)</param>
|
|
|
|
/// <short> Change contact photo</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Path to contact photo
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact/{contactid:int}/changephoto")]
|
2020-04-22 20:46:49 +00:00
|
|
|
public string ChangeContactPhoto(int contactid, IEnumerable<IFormFile> photo)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (contactid <= 0)
|
|
|
|
throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contact = _daoFactory.GetContactDao().GetByID(contactid);
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (contact == null || !_crmSecurity.CanAccessTo(contact))
|
2020-04-16 19:41:37 +00:00
|
|
|
throw new ItemNotFoundException();
|
|
|
|
|
|
|
|
var firstPhoto = photo != null ? photo.FirstOrDefault() : null;
|
2020-04-22 20:46:49 +00:00
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
if (firstPhoto == null)
|
|
|
|
throw new ArgumentException();
|
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
var fileStream = firstPhoto.OpenReadStream();
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
if (firstPhoto.Length == 0 ||
|
2021-02-24 16:50:07 +00:00
|
|
|
!firstPhoto.ContentType.StartsWith("image/") ||
|
2020-04-22 20:46:49 +00:00
|
|
|
!fileStream.CanRead)
|
2020-04-16 19:41:37 +00:00
|
|
|
throw new InvalidOperationException(CRMErrorsResource.InvalidFile);
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (_setupInfo.MaxImageUploadSize > 0 &&
|
|
|
|
_setupInfo.MaxImageUploadSize < firstPhoto.Length)
|
|
|
|
throw new Exception(_fileSizeComment.GetFileImageSizeNote(CRMCommonResource.ErrorMessage_UploadFileSize, false));
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _contactPhotoManager.UploadPhoto(fileStream, contactid, false).Url;
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Changes the photo for the contact with the ID specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="contactid">Contact ID</param>
|
|
|
|
/// <param name="photourl">contact photo url</param>
|
|
|
|
/// <short> Change contact photo</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Path to contact photo
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact/{contactid:int}/changephotobyurl")]
|
|
|
|
public string ChangeContactPhoto(int contactid, string photourl)
|
|
|
|
{
|
|
|
|
if (contactid <= 0 || string.IsNullOrEmpty(photourl)) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contact = _daoFactory.GetContactDao().GetByID(contactid);
|
|
|
|
if (contact == null || !_crmSecurity.CanAccessTo(contact)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _contactPhotoManager.UploadPhoto(photourl, contactid, false).Url;
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Merge two selected contacts
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="fromcontactid">the first contact ID for merge</param>
|
|
|
|
/// <param name="tocontactid">the second contact ID for merge</param>
|
|
|
|
/// <short>Merge contacts</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <exception cref="SecurityException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact/merge")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public ContactDto MergeContacts(int fromcontactid, int tocontactid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (fromcontactid <= 0 || tocontactid <= 0) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var fromContact = _daoFactory.GetContactDao().GetByID(fromcontactid);
|
|
|
|
var toContact = _daoFactory.GetContactDao().GetByID(tocontactid);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (fromContact == null || toContact == null) throw new ItemNotFoundException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (!_crmSecurity.CanEdit(fromContact) || !_crmSecurity.CanEdit(toContact)) throw _crmSecurity.CreateSecurityException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetContactDao().MergeDublicate(fromcontactid, tocontactid);
|
|
|
|
var resultContact = _daoFactory.GetContactDao().GetByID(tocontactid);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
var messageAction = resultContact is Person ? MessageAction.PersonsMerged : MessageAction.CompaniesMerged;
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(messageAction, _messageTarget.Create(new[] { fromContact.ID, toContact.ID }), fromContact.GetTitle(), toContact.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mapper.Map<ContactDto>(resultContact);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates the selected person with the parameters (first name, last name, description, etc.) specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="personid">Person ID</param>
|
|
|
|
/// <param name="firstName">First name</param>
|
|
|
|
/// <param name="lastName">Last name</param>
|
|
|
|
/// <param optional="true" name="jobTitle">Post</param>
|
|
|
|
/// <param optional="true" name="companyId">Company ID</param>
|
|
|
|
/// <param optional="true" name="about">Person description text</param>
|
|
|
|
/// <param name="shareType">Person privacy: 0 - not shared, 1 - shared for read/write, 2 - shared for read only</param>
|
|
|
|
/// <param optional="true" name="managerList">List of persons managers</param>
|
|
|
|
/// <param optional="true" name="customFieldList">User field list</param>
|
|
|
|
/// <param optional="true" name="photo">Contact photo (upload using multipart/form-data)</param>
|
|
|
|
/// <short>Update person</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>Person</returns>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
[Update(@"contact/person/{personid:int}")]
|
2021-06-23 19:32:56 +00:00
|
|
|
public PersonDto UpdatePerson([FromQuery] int personid, [FromBody] CreateOrUpdatePersonRequestDto inDto)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-05 20:06:49 +00:00
|
|
|
string firstName = inDto.FirstName;
|
|
|
|
string lastName = inDto.LastName;
|
|
|
|
string jobTitle = inDto.JobTitle;
|
|
|
|
int companyId = inDto.CompanyId;
|
|
|
|
string about = inDto.About;
|
|
|
|
ShareType shareType = inDto.ShareType;
|
|
|
|
IEnumerable<Guid> managerList = inDto.ManagerList;
|
|
|
|
IEnumerable<ItemKeyValuePair<int, string>> customFieldList = inDto.CustomFieldList;
|
|
|
|
IEnumerable<IFormFile> photo = inDto.Photos;
|
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
if (personid <= 0 || string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName)) throw new ArgumentException();
|
|
|
|
|
|
|
|
var peopleInst = new Person
|
2021-02-24 16:50:07 +00:00
|
|
|
{
|
|
|
|
ID = personid,
|
|
|
|
FirstName = firstName,
|
|
|
|
LastName = lastName,
|
|
|
|
JobTitle = jobTitle,
|
|
|
|
CompanyID = companyId,
|
|
|
|
About = about,
|
|
|
|
ShareType = shareType
|
|
|
|
};
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetContactDao().UpdateContact(peopleInst);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
peopleInst = (Person)_daoFactory.GetContactDao().GetByID(peopleInst.ID);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
var managerListLocal = managerList != null ? managerList.ToList() : new List<Guid>();
|
|
|
|
if (managerListLocal.Any())
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
_crmSecurity.SetAccessTo(peopleInst, managerListLocal);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (customFieldList != null)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var existingCustomFieldList = _daoFactory.GetCustomFieldDao().GetFieldsDescription(EntityType.Person).Select(fd => fd.ID).ToList();
|
2020-04-16 19:41:37 +00:00
|
|
|
foreach (var field in customFieldList)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(field.Value) || !existingCustomFieldList.Contains(field.Key)) continue;
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetCustomFieldDao().SetFieldValue(EntityType.Person, peopleInst.ID, field.Key, field.Value);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var outDto = (PersonDto)_mapper.Map<ContactDto>(peopleInst);
|
2020-04-22 20:46:49 +00:00
|
|
|
|
|
|
|
var photoList = photo != null ? photo.ToList() : new List<IFormFile>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (photoList.Any())
|
|
|
|
{
|
2021-03-05 20:06:49 +00:00
|
|
|
outDto.SmallFotoUrl = ChangeContactPhoto(peopleInst.ID, photoList);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.PersonUpdated, _messageTarget.Create(peopleInst.ID), peopleInst.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-05 20:06:49 +00:00
|
|
|
return outDto;
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates the company with the parameters specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="companyName">Company name</param>
|
|
|
|
/// <param optional="true" name="about">Company description text</param>
|
|
|
|
/// <param optional="true" name="personList">Linked person list</param>
|
|
|
|
/// <param name="shareType">Company privacy: 0 - not shared, 1 - shared for read/write, 2 - shared for read only</param>
|
|
|
|
/// <param optional="true" name="managerList">List of managers for the company</param>
|
|
|
|
/// <param optional="true" name="customFieldList">User field list</param>
|
|
|
|
/// <param optional="true" name="photo">Contact photo (upload using multipart/form-data)</param>
|
|
|
|
/// <short>Create company</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>Company</returns>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
[Create(@"contact/company")]
|
2021-06-23 19:32:56 +00:00
|
|
|
public CompanyDto CreateCompany([FromBody] CreateOrUpdateCompanyRequestDto inDto)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-05 20:06:49 +00:00
|
|
|
var personList = inDto.PersonList;
|
|
|
|
string companyName = inDto.CompanyName;
|
|
|
|
string about = inDto.About;
|
|
|
|
ShareType shareType = inDto.ShareType;
|
|
|
|
IEnumerable<Guid> managerList = inDto.ManagerList;
|
|
|
|
IEnumerable<ItemKeyValuePair<int, string>> customFieldList = inDto.CustomFieldList;
|
|
|
|
IEnumerable<IFormFile> photo = inDto.Photos;
|
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
var companyInst = new Company
|
2021-02-24 16:50:07 +00:00
|
|
|
{
|
|
|
|
CompanyName = companyName,
|
|
|
|
About = about,
|
|
|
|
ShareType = shareType
|
|
|
|
};
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
companyInst.ID = _daoFactory.GetContactDao().SaveContact(companyInst);
|
|
|
|
companyInst.CreateBy = _securityContext.CurrentAccount.ID;
|
2020-04-16 19:41:37 +00:00
|
|
|
companyInst.CreateOn = DateTime.UtcNow;
|
|
|
|
|
|
|
|
if (personList != null)
|
|
|
|
{
|
|
|
|
foreach (var personID in personList)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var person = _daoFactory.GetContactDao().GetByID(personID);
|
|
|
|
if (person == null || !_crmSecurity.CanAccessTo(person)) continue;
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
AddPeopleToCompany(companyInst.ID, personID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var managerListLocal = managerList != null ? managerList.ToList() : new List<Guid>();
|
|
|
|
if (managerListLocal.Any())
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
_crmSecurity.SetAccessTo(companyInst, managerListLocal);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (customFieldList != null)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var existingCustomFieldList = _daoFactory.GetCustomFieldDao().GetFieldsDescription(EntityType.Company).Select(fd => fd.ID).ToList();
|
2020-04-16 19:41:37 +00:00
|
|
|
foreach (var field in customFieldList)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(field.Value) || !existingCustomFieldList.Contains(field.Key)) continue;
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetCustomFieldDao().SetFieldValue(EntityType.Company, companyInst.ID, field.Key, field.Value);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var wrapper = (CompanyDto)_mapper.Map<ContactDto>(companyInst);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
var photoList = photo != null ? photo.ToList() : new List<IFormFile>();
|
2020-04-16 19:41:37 +00:00
|
|
|
if (photoList.Any())
|
|
|
|
{
|
|
|
|
wrapper.SmallFotoUrl = ChangeContactPhoto(companyInst.ID, photoList);
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.CompanyCreated, _messageTarget.Create(companyInst.ID), companyInst.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Quickly creates the list of companies
|
|
|
|
/// </summary>
|
|
|
|
/// <short>
|
|
|
|
/// Quick company list creation
|
|
|
|
/// </short>
|
|
|
|
/// <param name="companyName">Company name</param>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>Contact list</returns>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
[Create(@"contact/company/quick")]
|
2021-06-23 19:32:56 +00:00
|
|
|
public IEnumerable<ContactBaseDto> CreateCompany([FromBody] IEnumerable<string> companyName)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (companyName == null) throw new ArgumentException();
|
|
|
|
|
|
|
|
var contacts = new List<Contact>();
|
|
|
|
var recordIndex = 0;
|
|
|
|
|
|
|
|
foreach (var item in companyName)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(item)) continue;
|
|
|
|
|
|
|
|
contacts.Add(new Company
|
2021-02-24 16:50:07 +00:00
|
|
|
{
|
|
|
|
ID = recordIndex++,
|
|
|
|
CompanyName = item,
|
|
|
|
ShareType = ShareType.None
|
|
|
|
});
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (contacts.Count == 0) return null;
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetContactDao().SaveContactList(contacts);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var selectedManagers = new List<Guid> { _securityContext.CurrentAccount.ID };
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
foreach (var ct in contacts)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
_crmSecurity.SetAccessTo(ct, selectedManagers);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return contacts.ConvertAll(x => _mapper.Map<ContactBaseDto>(x));
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Quickly creates the list of persons with the first and last names specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <short>
|
|
|
|
/// Quick person list creation
|
|
|
|
/// </short>
|
|
|
|
/// <param name="data">Pairs: user first name, user last name</param>
|
|
|
|
/// <remarks>
|
|
|
|
/// <![CDATA[
|
|
|
|
/// data has format
|
|
|
|
/// [{key: 'First name 1', value: 'Last name 1'},{key: 'First name 2', value: 'Last name 2'}]
|
|
|
|
/// ]]>
|
|
|
|
/// </remarks>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>Contact list</returns>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
[Create(@"contact/person/quick")]
|
2021-06-23 19:32:56 +00:00
|
|
|
public IEnumerable<ContactBaseDto> CreatePerson([FromBody] IEnumerable<ItemKeyValuePair<string, string>> data)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (data == null) return null;
|
|
|
|
|
|
|
|
var contacts = new List<Contact>();
|
|
|
|
var recordIndex = 0;
|
|
|
|
|
|
|
|
foreach (var item in data)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(item.Key) || string.IsNullOrEmpty(item.Value)) continue;
|
|
|
|
|
|
|
|
contacts.Add(new Person
|
2021-02-24 16:50:07 +00:00
|
|
|
{
|
|
|
|
ID = recordIndex++,
|
|
|
|
FirstName = item.Key,
|
|
|
|
LastName = item.Value,
|
|
|
|
ShareType = ShareType.None
|
|
|
|
});
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (contacts.Count == 0) return null;
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetContactDao().SaveContactList(contacts);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var selectedManagers = new List<Guid> { _securityContext.CurrentAccount.ID };
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
foreach (var ct in contacts)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
_crmSecurity.SetAccessTo(ct, selectedManagers);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.PersonsCreated, _messageTarget.Create(contacts.Select(x => x.ID)), contacts.Select(x => x.GetTitle()));
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return contacts.ConvertAll(x => _mapper.Map<ContactBaseDto>(x));
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates the selected company with the parameters specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="companyid">Company ID</param>
|
|
|
|
/// <param name="companyName">Company name</param>
|
|
|
|
/// <param optional="true" name="about">Company description text</param>
|
|
|
|
/// <param name="shareType">Company privacy: 0 - not shared, 1 - shared for read/write, 2 - shared for read only</param>
|
|
|
|
/// <param optional="true" name="managerList">List of company managers</param>
|
|
|
|
/// <param optional="true" name="customFieldList">User field list</param>
|
|
|
|
/// <short>Update company</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Company
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact/company/{companyid:int}")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public CompanyDto UpdateCompany(
|
2021-06-23 19:32:56 +00:00
|
|
|
[FromRoute] int companyid,
|
|
|
|
[FromBody] CreateOrUpdateCompanyRequestDto intDto)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-05 20:06:49 +00:00
|
|
|
string companyName = intDto.CompanyName;
|
|
|
|
string about = intDto.About;
|
|
|
|
ShareType shareType = intDto.ShareType;
|
|
|
|
IEnumerable<Guid> managerList = intDto.ManagerList;
|
|
|
|
IEnumerable<ItemKeyValuePair<int, string>> customFieldList = intDto.CustomFieldList;
|
|
|
|
IEnumerable<IFormFile> photo = intDto.Photos;
|
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
var companyInst = new Company
|
2021-02-24 16:50:07 +00:00
|
|
|
{
|
|
|
|
ID = companyid,
|
|
|
|
CompanyName = companyName,
|
|
|
|
About = about,
|
|
|
|
ShareType = shareType
|
|
|
|
};
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetContactDao().UpdateContact(companyInst);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
companyInst = (Company)_daoFactory.GetContactDao().GetByID(companyInst.ID);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-02-24 16:50:07 +00:00
|
|
|
var managerListLocal = managerList != null ? managerList.ToList() : new List<Guid>();
|
2020-04-16 19:41:37 +00:00
|
|
|
if (managerListLocal.Any())
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
_crmSecurity.SetAccessTo(companyInst, managerListLocal);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (customFieldList != null)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var existingCustomFieldList = _daoFactory.GetCustomFieldDao().GetFieldsDescription(EntityType.Company).Select(fd => fd.ID).ToList();
|
2020-04-16 19:41:37 +00:00
|
|
|
foreach (var field in customFieldList)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(field.Value) || !existingCustomFieldList.Contains(field.Key)) continue;
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetCustomFieldDao().SetFieldValue(EntityType.Company, companyInst.ID, field.Key, field.Value);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.CompanyUpdated, _messageTarget.Create(companyInst.ID), companyInst.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return (CompanyDto)_mapper.Map<ContactDto>(companyInst);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates the selected contact status
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="contactid">Contact ID</param>
|
|
|
|
/// <param name="contactStatusid">Contact status ID</param>
|
|
|
|
/// <short>Update status in contact by id</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Company
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact/{contactid:int}/status")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public ContactDto UpdateContactStatus(int contactid, int contactStatusid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (contactid <= 0 || contactStatusid < 0) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var dao = _daoFactory.GetContactDao();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (contactStatusid > 0)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var curListItem = _daoFactory.GetListItemDao().GetByID(contactStatusid);
|
2020-04-16 19:41:37 +00:00
|
|
|
if (curListItem == null) throw new ItemNotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
var companyInst = dao.GetByID(contactid);
|
2021-03-19 16:56:26 +00:00
|
|
|
if (companyInst == null || !_crmSecurity.CanAccessTo(companyInst)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (!_crmSecurity.CanEdit(companyInst)) throw _crmSecurity.CreateSecurityException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-02-24 16:50:07 +00:00
|
|
|
dao.UpdateContactStatus(new List<int> { companyInst.ID }, contactStatusid);
|
2020-04-16 19:41:37 +00:00
|
|
|
companyInst.StatusID = contactStatusid;
|
|
|
|
|
|
|
|
var messageAction = companyInst is Company ? MessageAction.CompanyUpdatedTemperatureLevel : MessageAction.PersonUpdatedTemperatureLevel;
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(messageAction, _messageTarget.Create(companyInst.ID), companyInst.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mapper.Map<ContactDto>(companyInst);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates status of the selected company and all its participants
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="companyid">Company ID</param>
|
|
|
|
/// <param name="contactStatusid">Contact status ID</param>
|
|
|
|
/// <short>Update company and participants status</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Company
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact/company/{companyid:int}/status")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public ContactDto UpdateCompanyAndParticipantsStatus(int companyid, int contactStatusid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (companyid <= 0 || contactStatusid < 0) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var dao = _daoFactory.GetContactDao();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (contactStatusid > 0)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var curListItem = _daoFactory.GetListItemDao().GetByID(contactStatusid);
|
2020-04-16 19:41:37 +00:00
|
|
|
if (curListItem == null) throw new ItemNotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
var companyInst = dao.GetByID(companyid);
|
2021-03-19 16:56:26 +00:00
|
|
|
if (companyInst == null || !_crmSecurity.CanAccessTo(companyInst)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (companyInst is Person) throw new Exception(CRMErrorsResource.ContactIsNotCompany);
|
|
|
|
|
|
|
|
var forUpdateStatus = new List<int>();
|
|
|
|
forUpdateStatus.Add(companyInst.ID);
|
|
|
|
|
|
|
|
var members = dao.GetMembersIDsAndShareType(companyInst.ID);
|
|
|
|
foreach (var m in members)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
if (_crmSecurity.CanAccessTo(m.Key, EntityType.Person, m.Value, 0))
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
forUpdateStatus.Add(m.Key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dao.UpdateContactStatus(forUpdateStatus, contactStatusid);
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.CompanyUpdatedTemperatureLevel, _messageTarget.Create(companyInst.ID), companyInst.GetTitle());
|
|
|
|
_messageService.Send(MessageAction.CompanyUpdatedPersonsTemperatureLevel, _messageTarget.Create(companyInst.ID), companyInst.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mapper.Map<ContactDto>(companyInst);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates status of the selected person, related company and all its participants
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="personid">Person ID</param>
|
|
|
|
/// <param name="contactStatusid">Contact status ID</param>
|
|
|
|
/// <short>Update person, related company and participants status</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Person
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact/person/{personid:int}/status")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public ContactDto UpdatePersonAndItsCompanyStatus(int personid, int contactStatusid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (personid <= 0 || contactStatusid < 0) throw new ArgumentException();
|
|
|
|
|
|
|
|
if (contactStatusid > 0)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var curListItem = _daoFactory.GetListItemDao().GetByID(contactStatusid);
|
2020-04-16 19:41:37 +00:00
|
|
|
if (curListItem == null) throw new ItemNotFoundException();
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var dao = _daoFactory.GetContactDao();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
var personInst = dao.GetByID(personid);
|
2021-03-19 16:56:26 +00:00
|
|
|
if (personInst == null || !_crmSecurity.CanAccessTo(personInst)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (personInst is Company) throw new Exception(CRMErrorsResource.ContactIsNotPerson);
|
|
|
|
|
|
|
|
var forUpdateStatus = new List<int>();
|
|
|
|
|
|
|
|
var companyID = ((Person)personInst).CompanyID;
|
|
|
|
if (companyID != 0)
|
|
|
|
{
|
|
|
|
var companyInst = dao.GetByID(companyID);
|
|
|
|
if (companyInst == null) throw new ItemNotFoundException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (!_crmSecurity.CanAccessTo(companyInst))
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
forUpdateStatus.Add(personInst.ID);
|
|
|
|
dao.UpdateContactStatus(forUpdateStatus, contactStatusid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
forUpdateStatus.Add(companyInst.ID);
|
|
|
|
|
|
|
|
var members = dao.GetMembersIDsAndShareType(companyInst.ID);
|
|
|
|
foreach (var m in members)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
if (_crmSecurity.CanAccessTo(m.Key, EntityType.Person, m.Value, 0))
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
forUpdateStatus.Add(m.Key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dao.UpdateContactStatus(forUpdateStatus, contactStatusid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
forUpdateStatus.Add(personInst.ID);
|
|
|
|
dao.UpdateContactStatus(forUpdateStatus, contactStatusid);
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.PersonUpdatedTemperatureLevel, _messageTarget.Create(personInst.ID), personInst.GetTitle());
|
|
|
|
_messageService.Send(MessageAction.PersonUpdatedCompanyTemperatureLevel, _messageTarget.Create(personInst.ID), personInst.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
personInst = dao.GetByID(personInst.ID);
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mapper.Map<ContactDto>(personInst);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get access rights to the contact with the ID specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <short>Get contact access rights</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
///<exception cref="ArgumentException"></exception>
|
|
|
|
///<exception cref="ItemNotFoundException"></exception>
|
|
|
|
///<exception cref="SecurityException"></exception>
|
|
|
|
/// <returns>User list</returns>
|
|
|
|
[Read(@"contact/{contactid:int}/access")]
|
|
|
|
public IEnumerable<EmployeeWraper> GetContactAccessList(int contactid)
|
|
|
|
{
|
|
|
|
if (contactid <= 0) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contact = _daoFactory.GetContactDao().GetByID(contactid);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (contact == null) throw new ItemNotFoundException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (!_crmSecurity.CanAccessTo(contact)) throw _crmSecurity.CreateSecurityException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _crmSecurity.IsPrivate(contact)
|
|
|
|
? _crmSecurity.GetAccessSubjectTo(contact)
|
|
|
|
.Select(item => _employeeWraperHelper.Get(item.Key))
|
2020-04-16 19:41:37 +00:00
|
|
|
: new List<EmployeeWraper>();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets access rights for other users to the contact with the ID specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="contactid">Contact ID</param>
|
|
|
|
/// <param name="isShared">Contact privacy: private or not</param>
|
|
|
|
/// <param name="managerList">List of managers</param>
|
|
|
|
/// <short>Set contact access rights</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
///<exception cref="ArgumentException"></exception>
|
|
|
|
///<exception cref="SecurityException"></exception>
|
|
|
|
///<exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact/{contactid:int}/access")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public ContactDto SetAccessToContact(int contactid, bool isShared, IEnumerable<Guid> managerList)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (contactid <= 0) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contact = _daoFactory.GetContactDao().GetByID(contactid);
|
2020-04-16 19:41:37 +00:00
|
|
|
if (contact == null) throw new ItemNotFoundException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (!_crmSecurity.CanEdit(contact)) throw _crmSecurity.CreateSecurityException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
SetAccessToContact(contact, isShared, managerList, false);
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var wrapper = _mapper.Map<ContactDto>(contact);
|
2020-04-22 20:46:49 +00:00
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetAccessToContact(Contact contact, bool isShared, IEnumerable<Guid> managerList, bool isNotify)
|
|
|
|
{
|
|
|
|
var managerListLocal = managerList != null ? managerList.Distinct().ToList() : new List<Guid>();
|
|
|
|
if (managerListLocal.Any())
|
|
|
|
{
|
|
|
|
if (isNotify)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var notifyUsers = managerListLocal.Where(n => n != _securityContext.CurrentAccount.ID).ToArray();
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
if (contact is Person)
|
2021-03-19 16:56:26 +00:00
|
|
|
_notifyClient.SendAboutSetAccess(EntityType.Person, contact.ID, _daoFactory, notifyUsers);
|
2020-04-16 19:41:37 +00:00
|
|
|
else
|
2021-03-19 16:56:26 +00:00
|
|
|
_notifyClient.SendAboutSetAccess(EntityType.Company, contact.ID, _daoFactory, notifyUsers);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_crmSecurity.SetAccessTo(contact, managerListLocal);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
_crmSecurity.MakePublic(contact);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetContactDao().MakePublic(contact.ID, isShared);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets access rights for other users to the list of contacts with the IDs specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="contactid">Contact ID list</param>
|
|
|
|
/// <param name="isShared">Company privacy: shared or not</param>
|
|
|
|
/// <param name="managerList">List of managers</param>
|
|
|
|
/// <short>Set contact access rights</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact/access")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactDto> SetAccessToBatchContact(
|
2021-03-17 11:50:13 +00:00
|
|
|
[FromBody] SetAccessToBatchContactRequestDto inDto)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-05 20:06:49 +00:00
|
|
|
var contactid = inDto.ContactID;
|
|
|
|
var isShared = inDto.isShared;
|
|
|
|
var managerList = inDto.ManagerList;
|
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
if (contactid == null) throw new ArgumentException();
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
var result = new List<ContactDto>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
foreach (var id in contactid)
|
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
var contactDto = SetAccessToContact(id, isShared, managerList);
|
|
|
|
result.Add(contactDto);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets access rights for the selected user to the list of contacts with the parameters specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="isPrivate">Contact privacy: private or not</param>
|
|
|
|
/// <param name="managerList">List of managers</param>
|
|
|
|
/// <param optional="true" name="tags">Tag</param>
|
|
|
|
/// <param optional="true" name="contactStage">Contact stage ID (warmth)</param>
|
|
|
|
/// <param optional="true" name="contactType">Contact type ID</param>
|
|
|
|
/// <param optional="true" name="contactListView" remark="Allowed values: Company, Person, WithOpportunity"></param>
|
|
|
|
/// <param optional="true" name="fromDate">Start date</param>
|
|
|
|
/// <param optional="true" name="toDate">End date</param>
|
|
|
|
/// <short>Set contact access rights</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact/filter/access")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactDto> SetAccessToBatchContact(
|
2021-06-23 19:32:56 +00:00
|
|
|
[FromBody] SetAccessToBatchContactByFilterRequestDto inDto)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-05 20:06:49 +00:00
|
|
|
IEnumerable<String> tags = inDto.Tags;
|
|
|
|
int? contactStage = inDto.ContactStage;
|
|
|
|
int? contactType = inDto.ContactType;
|
|
|
|
ContactListViewType contactListView = inDto.ContactListView;
|
|
|
|
ApiDateTime fromDate = inDto.FromDate;
|
|
|
|
ApiDateTime toDate = inDto.ToDate;
|
|
|
|
bool isPrivate = inDto.isPrivate;
|
|
|
|
IEnumerable<Guid> managerList = inDto.ManagerList;
|
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
int contactStageInt = contactStage.HasValue ? contactStage.Value : -1;
|
|
|
|
int contactTypeInt = contactType.HasValue ? contactType.Value : -1;
|
|
|
|
|
|
|
|
var result = new List<Contact>();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contacts = _daoFactory.GetContactDao().GetContacts(
|
|
|
|
_apiContext.FilterValue,
|
2020-04-16 19:41:37 +00:00
|
|
|
tags,
|
|
|
|
contactStageInt,
|
|
|
|
contactTypeInt,
|
|
|
|
contactListView,
|
|
|
|
fromDate, toDate,
|
|
|
|
0, 0, null);
|
|
|
|
|
|
|
|
if (!contacts.Any())
|
2021-03-09 15:37:16 +00:00
|
|
|
return Enumerable.Empty<ContactDto>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
foreach (var contact in contacts)
|
|
|
|
{
|
|
|
|
if (contact == null)
|
|
|
|
throw new ItemNotFoundException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (!_crmSecurity.CanEdit(contact)) continue;
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
SetAccessToContact(contact, isPrivate, managerList, false);
|
|
|
|
|
|
|
|
result.Add(contact);
|
|
|
|
}
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mapper.Map<List<Contact>, List<ContactDto>>(result);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Deletes the contact with the ID specified in the request from the portal
|
|
|
|
/// </summary>
|
|
|
|
/// <short>Delete contact</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <param name="contactid">Contact ID</param>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact
|
|
|
|
/// </returns>
|
|
|
|
[Delete(@"contact/{contactid:int}")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public ContactDto DeleteContact(int contactid)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (contactid <= 0) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contact = _daoFactory.GetContactDao().DeleteContact(contactid);
|
2020-04-16 19:41:37 +00:00
|
|
|
if (contact == null) throw new ItemNotFoundException();
|
|
|
|
|
|
|
|
var messageAction = contact is Person ? MessageAction.PersonDeleted : MessageAction.CompanyDeleted;
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(messageAction, _messageTarget.Create(contact.ID), contact.GetTitle());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mapper.Map<ContactDto>(contact);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Deletes the group of contacts with the IDs specified in the request
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="contactids">Contact ID list</param>
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
/// <exception cref="ItemNotFoundException"></exception>
|
|
|
|
/// <short>Delete contact group</short>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
[Update(@"contact")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactBaseDto> DeleteBatchContacts(IEnumerable<int> contactids)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (contactids == null) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contacts = _daoFactory.GetContactDao().DeleteBatchContact(contactids.ToArray());
|
|
|
|
_messageService.Send(MessageAction.ContactsDeleted, _messageTarget.Create(contactids), contacts.Select(c => c.GetTitle()));
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return contacts.Select(x => _mapper.Map<ContactBaseDto>(x));
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the list of 30 contacts in the CRM module with prefix
|
|
|
|
/// </summary>
|
|
|
|
/// <param optional="true" name="prefix"></param>
|
|
|
|
/// <param optional="false" name="searchType" remark="Allowed values: -1 (Any), 0 (Company), 1 (Persons), 2 (PersonsWithoutCompany), 3 (CompaniesAndPersonsWithoutCompany)">searchType</param>
|
|
|
|
/// <param optional="true" name="entityType"></param>
|
|
|
|
/// <param optional="true" name="entityID"></param>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
/// <visible>false</visible>
|
|
|
|
[Read(@"contact/byprefix")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactBaseWithPhoneDto> GetContactsByPrefix(string prefix, int searchType, EntityType entityType, int entityID)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
var result = new List<ContactBaseWithPhoneDto>();
|
2020-04-16 19:41:37 +00:00
|
|
|
var allContacts = new List<Contact>();
|
|
|
|
|
|
|
|
if (entityID > 0)
|
|
|
|
{
|
|
|
|
var findedContacts = new List<Contact>();
|
|
|
|
switch (entityType)
|
|
|
|
{
|
|
|
|
case EntityType.Opportunity:
|
2021-03-19 16:56:26 +00:00
|
|
|
allContacts = _daoFactory.GetContactDao().GetContacts(_daoFactory.GetDealDao().GetMembers(entityID));
|
2020-04-16 19:41:37 +00:00
|
|
|
break;
|
|
|
|
case EntityType.Case:
|
2021-03-19 16:56:26 +00:00
|
|
|
allContacts = _daoFactory.GetContactDao().GetContacts(_daoFactory.GetCasesDao().GetMembers(entityID));
|
2020-04-16 19:41:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var c in allContacts)
|
|
|
|
{
|
|
|
|
var person = c as Person;
|
|
|
|
if (person != null)
|
|
|
|
{
|
|
|
|
var people = person;
|
2020-04-18 17:49:09 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (_userFormatter.GetUserName(people.FirstName, people.LastName).IndexOf(prefix, StringComparison.Ordinal) != -1)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
findedContacts.Add(person);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var company = (Company)c;
|
|
|
|
if (company.CompanyName.IndexOf(prefix, StringComparison.Ordinal) != -1)
|
|
|
|
{
|
|
|
|
findedContacts.Add(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-19 16:56:26 +00:00
|
|
|
result.AddRange(findedContacts.Select(x => _mapper.Map<ContactBaseWithPhoneDto>(x)));
|
2020-04-22 20:46:49 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_apiContext.SetTotalCount(findedContacts.Count);
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const int maxItemCount = 30;
|
2021-03-19 16:56:26 +00:00
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
if (searchType < -1 || searchType > 3) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
allContacts = _daoFactory.GetContactDao().GetContactsByPrefix(prefix, searchType, 0, maxItemCount);
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
result.AddRange(allContacts.Select(x => _mapper.Map<ContactBaseWithPhoneDto>(x)));
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the list contacts in the CRM module with contact information
|
|
|
|
/// </summary>
|
|
|
|
/// <param optional="false" name="infoType">Contact information type</param>
|
|
|
|
/// <param optional="false" name="data">Data</param>
|
|
|
|
/// <param optional="true" name="category">Category</param>
|
|
|
|
/// <param optional="true" name="isPrimary">Contact importance: primary or not</param>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns>
|
|
|
|
/// Contact list
|
|
|
|
/// </returns>
|
|
|
|
[Read(@"contact/bycontactinfo")]
|
2021-03-09 15:37:16 +00:00
|
|
|
public IEnumerable<ContactDto> GetContactsByContactInfo(ContactInfoType? infoType, String data, int? category, bool? isPrimary)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (!infoType.HasValue) throw new ArgumentException();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var ids = _daoFactory.GetContactDao().GetContactIDsByContactInfo(infoType.Value, data, category, isPrimary);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var result = _daoFactory.GetContactDao().GetContacts(ids.ToArray()).ConvertAll(x => _mapper.Map<ContactDto>(x));
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
///// <summary>
|
|
|
|
/////
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="contactid"></param>
|
|
|
|
///// <param name="count"></param>
|
|
|
|
///// <category>Contacts</category>
|
|
|
|
///// <returns></returns>
|
|
|
|
//[Read(@"contact/{contactid:int}/tweets")]
|
|
|
|
//public List<Message> GetUserTweets(int contactid, int count)
|
|
|
|
//{
|
|
|
|
// var MessageCount = 10;
|
|
|
|
// var twitterAccounts = DaoFactory.GetContactInfoDao().GetList(contactid, ContactInfoType.Twitter, null, null);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// if (twitterAccounts.Count == 0)
|
|
|
|
// throw new ResourceNotFoundException(
|
|
|
|
// Newtonsoft.Json.JsonConvert.SerializeObject(
|
|
|
|
// new
|
|
|
|
// {
|
|
|
|
// message = "",
|
|
|
|
// description = CRMSocialMediaResource.SocialMediaAccountNotFoundTwitter
|
|
|
|
// }
|
|
|
|
// ));
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// var apiInfo = TwitterApiHelper.GetTwitterApiInfoForCurrentUser();
|
|
|
|
// TwitterDataProvider twitterProvider = new TwitterDataProvider(apiInfo);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// List<Message> messages = new List<Message>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// foreach (var twitterAccount in twitterAccounts)
|
|
|
|
// {
|
|
|
|
// try
|
|
|
|
// {
|
|
|
|
// messages.AddRange(twitterProvider.GetUserTweets(twitterAccount.ID, twitterAccount.Data, MessageCount));
|
|
|
|
// }
|
|
|
|
// catch (ResourceNotFoundException ex)
|
|
|
|
// {
|
|
|
|
// throw new ResourceNotFoundException(
|
|
|
|
// Newtonsoft.Json.JsonConvert.SerializeObject(
|
|
|
|
// new
|
|
|
|
// {
|
|
|
|
// message = ex.Message,
|
|
|
|
// description = String.Format("{0}: {1}", CRMSocialMediaResource.ErrorUnknownTwitterAccount, twitterAccount.Data)
|
|
|
|
// }
|
|
|
|
// ));
|
|
|
|
// }
|
|
|
|
// catch (Exception ex)
|
|
|
|
// {
|
|
|
|
// throw new Exception(
|
|
|
|
// Newtonsoft.Json.JsonConvert.SerializeObject(
|
|
|
|
// new
|
|
|
|
// {
|
|
|
|
// message = ex.Message,
|
|
|
|
// description = String.Format("{0}: {1}", CRMSocialMediaResource.ErrorUnknownTwitterAccount, twitterAccount.Data)
|
|
|
|
// }
|
|
|
|
// ));
|
|
|
|
// }
|
|
|
|
// }
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// return messages.OrderByDescending(m => m.PostedOn).Take(MessageCount).ToList();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
//}
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
///// <summary>
|
|
|
|
/////
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="searchText"></param>
|
|
|
|
///// <category>Contacts</category>
|
|
|
|
///// <returns></returns>
|
|
|
|
//[Read(@"contact/twitterprofile")]
|
|
|
|
//public List<TwitterUserInfo> FindTwitterProfiles(string searchText)
|
|
|
|
//{
|
|
|
|
// try
|
|
|
|
// {
|
|
|
|
// TwitterApiInfo apiInfo = TwitterApiHelper.GetTwitterApiInfoForCurrentUser();
|
|
|
|
// if (apiInfo == null)
|
|
|
|
// throw new SocialMediaAccountNotFound(CRMSocialMediaResource.SocialMediaAccountNotFoundTwitter);
|
|
|
|
|
|
|
|
// TwitterDataProvider provider = new TwitterDataProvider(apiInfo);
|
|
|
|
// List<TwitterUserInfo> users = provider.FindUsers(searchText);
|
|
|
|
// /*List<TwitterUserInfo> users = new List<TwitterUserInfo>();
|
|
|
|
// users.Add(new TwitterUserInfo { Description = "I'm a cool user", SmallImageUrl = "http://localhost/TeamLab/products/crm/data/0/photos/00/00/10/contact_10_50_50.jpg", UserName = "User", ScreenName = "user", UserID = 1 });
|
|
|
|
// users.Add(new TwitterUserInfo { Description = "I'm a cool user", SmallImageUrl = "http://localhost/TeamLab/products/crm/data/0/photos/00/00/10/contact_10_50_50.jpg", UserName = "User", ScreenName = "user", UserID = 1 });
|
|
|
|
// users.Add(new TwitterUserInfo { Description = "I'm a cool user", SmallImageUrl = "http://localhost/TeamLab/products/crm/data/0/photos/00/00/10/contact_10_50_50.jpg", UserName = "User", ScreenName = "user", UserID = 1 });*/
|
|
|
|
// return users;
|
|
|
|
// }
|
|
|
|
// catch (Exception ex) {
|
2021-03-10 15:38:56 +00:00
|
|
|
// throw new SocialMediaUI(DaoFactory).ProcessError(ex, "ASC.CRM.Api.CRMApi.FindTwitterProfiles");
|
2020-04-22 20:46:49 +00:00
|
|
|
// }
|
|
|
|
//}
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="contactId"></param>
|
|
|
|
/// <param name="contactType"></param>
|
|
|
|
/// <param name="uploadOnly"></param>
|
|
|
|
/// <category>Contacts</category>
|
|
|
|
/// <returns></returns>
|
|
|
|
[Delete(@"contact/{contactid:int}/avatar")]
|
|
|
|
public string DeleteContactAvatar(int contactId, string contactType, bool uploadOnly)
|
|
|
|
{
|
|
|
|
bool isCompany;
|
|
|
|
|
|
|
|
if (contactId != 0)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var contact = _daoFactory.GetContactDao().GetByID(contactId);
|
|
|
|
if (contact == null || !_crmSecurity.CanAccessTo(contact)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (!_crmSecurity.CanEdit(contact)) throw _crmSecurity.CreateSecurityException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
isCompany = contact is Company;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isCompany = contactType != "people";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!uploadOnly)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
_contactPhotoManager.DeletePhoto(contactId);
|
|
|
|
return _contactPhotoManager.GetBigSizePhoto(0, isCompany);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
///// <summary>
|
|
|
|
/////
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="contactId"></param>
|
|
|
|
///// <category>Contacts</category>
|
|
|
|
///// <returns></returns>
|
|
|
|
//[Read(@"contact/{contactid:int}/socialmediaavatar")]
|
|
|
|
//public List<SocialMediaImageDescription> GetContactSMImages(int contactId)
|
|
|
|
//{
|
|
|
|
// return new SocialMediaUI(DaoFactory).GetContactSMImages(contactId);
|
|
|
|
//}
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
///// <summary>
|
|
|
|
/////
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="socialNetworks"></param>
|
|
|
|
///// <category>Contacts</category>
|
|
|
|
///// <returns></returns>
|
|
|
|
//[Create(@"contact/socialmediaavatar")]
|
2021-03-09 15:37:16 +00:00
|
|
|
//public List<SocialMediaImageDescription> GetContactSMImagesByNetworks(List<ContactInfoDto> socialNetworks)
|
2020-04-22 20:46:49 +00:00
|
|
|
//{
|
|
|
|
// if (socialNetworks == null || socialNetworks.Count == 0)
|
|
|
|
// {
|
|
|
|
// return new List<SocialMediaImageDescription>();
|
|
|
|
// }
|
|
|
|
// var twitter = new List<String>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// foreach (var sn in socialNetworks)
|
|
|
|
// {
|
|
|
|
// if (sn.InfoType == ContactInfoType.Twitter) twitter.Add(sn.Data);
|
|
|
|
// }
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// return new SocialMediaUI(DaoFactory).GetContactSMImages(twitter);
|
|
|
|
//}
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
///// <summary>
|
|
|
|
/////
|
|
|
|
///// </summary>
|
|
|
|
///// <param name="contactId"></param>
|
|
|
|
///// <param name="socialNetwork"></param>
|
|
|
|
///// <param name="userIdentity"></param>
|
|
|
|
///// <param name="uploadOnly"></param>
|
|
|
|
///// <param name="tmpDirName" visible="false"></param>
|
|
|
|
///// <category>Contacts</category>
|
|
|
|
///// <returns></returns>
|
|
|
|
//[Update(@"contact/{contactid:int}/avatar")]
|
|
|
|
//public ContactPhotoManager.PhotoData UploadUserAvatarFromSocialNetwork(int contactId, SocialNetworks socialNetwork, string userIdentity, bool uploadOnly, string tmpDirName)
|
|
|
|
//{
|
|
|
|
// if (socialNetwork != SocialNetworks.Twitter)
|
|
|
|
// throw new ArgumentException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// if (contactId != 0)
|
|
|
|
// {
|
|
|
|
// var contact = DaoFactory.GetContactDao().GetByID(contactId);
|
|
|
|
// if (contact == null || !CRMSecurity.CanAccessTo(contact)) throw new ItemNotFoundException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// if (!CRMSecurity.CanEdit(contact)) throw CRMSecurity.CreateSecurityException();
|
|
|
|
// }
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// if (socialNetwork == SocialNetworks.Twitter)
|
|
|
|
// {
|
|
|
|
// var provider = new TwitterDataProvider(TwitterApiHelper.GetTwitterApiInfoForCurrentUser());
|
|
|
|
// var imageUrl = provider.GetUrlOfUserImage(userIdentity, TwitterDataProvider.ImageSize.Original);
|
|
|
|
// return UploadAvatar(contactId, imageUrl, uploadOnly, tmpDirName, false);
|
|
|
|
// }
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-22 20:46:49 +00:00
|
|
|
// return null;
|
|
|
|
//}
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-13 18:00:08 +00:00
|
|
|
/// <visible>false</visible>
|
|
|
|
[Create(@"contact/mailsmtp/send")]
|
|
|
|
public IProgressItem SendMailSMTPToContacts(
|
2021-03-17 11:50:13 +00:00
|
|
|
SendMailSMTPToContactsRequestDto inDto)
|
2021-03-13 18:00:08 +00:00
|
|
|
{
|
|
|
|
List<int> fileIDs = inDto.FileIDs;
|
|
|
|
List<int> contactIds = inDto.ContactIds;
|
|
|
|
String subject = inDto.Subject;
|
2021-03-15 11:36:22 +00:00
|
|
|
String body = inDto.Body;
|
2021-03-13 18:00:08 +00:00
|
|
|
bool storeInHistory = inDto.StoreInHistory;
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-13 18:00:08 +00:00
|
|
|
if (contactIds == null || contactIds.Count == 0 || String.IsNullOrEmpty(body)) throw new ArgumentException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contacts = _daoFactory.GetContactDao().GetContacts(contactIds.ToArray());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_messageService.Send(MessageAction.CrmSmtpMailSent, _messageTarget.Create(contactIds), contacts.Select(c => c.GetTitle()));
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mailSender.Start(fileIDs, contactIds, subject, body, storeInHistory);
|
2021-03-13 18:00:08 +00:00
|
|
|
}
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-13 18:00:08 +00:00
|
|
|
/// <visible>false</visible>
|
|
|
|
[Create(@"contact/mailsmtp/preview")]
|
2021-06-25 13:58:42 +00:00
|
|
|
public string GetMailSMTPToContactsPreview([FromBody] GetMailSMTPToContactsPreviewRequestDto inDto)
|
2021-03-13 18:00:08 +00:00
|
|
|
{
|
2021-06-25 13:58:42 +00:00
|
|
|
var contactId = inDto.ContactId;
|
|
|
|
var template = inDto.Template;
|
|
|
|
|
2021-03-13 18:00:08 +00:00
|
|
|
if (contactId == 0 || String.IsNullOrEmpty(template)) throw new ArgumentException();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var manager = new MailTemplateManager(_daoFactory);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-13 18:00:08 +00:00
|
|
|
return manager.Apply(template, contactId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
[Read(@"contact/mailsmtp/status")]
|
|
|
|
public IProgressItem GetMailSMTPToContactsStatus()
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
return _mailSender.GetStatus();
|
2021-03-13 18:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
[Update(@"contact/mailsmtp/cancel")]
|
|
|
|
public IProgressItem CancelMailSMTPToContacts()
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var progressItem = _mailSender.GetStatus();
|
2021-03-13 18:00:08 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_mailSender.Cancel();
|
2021-03-13 18:00:08 +00:00
|
|
|
|
|
|
|
return progressItem;
|
|
|
|
|
|
|
|
}
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
[Update(@"contact/{contactid:int}/creationdate")]
|
|
|
|
public void SetContactCreationDate(int contactId, ApiDateTime creationDate)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var dao = _daoFactory.GetContactDao();
|
2020-04-16 19:41:37 +00:00
|
|
|
var contact = dao.GetByID(contactId);
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (contact == null || !_crmSecurity.CanAccessTo(contact))
|
2020-04-16 19:41:37 +00:00
|
|
|
throw new ItemNotFoundException();
|
|
|
|
|
|
|
|
dao.SetContactCreationDate(contactId, creationDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
[Update(@"contact/{contactid:int}/lastmodifeddate")]
|
|
|
|
public void SetContactLastModifedDate(int contactId, ApiDateTime lastModifedDate)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var dao = _daoFactory.GetContactDao();
|
2020-04-16 19:41:37 +00:00
|
|
|
var contact = dao.GetByID(contactId);
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
if (contact == null || !_crmSecurity.CanAccessTo(contact))
|
2020-04-16 19:41:37 +00:00
|
|
|
throw new ItemNotFoundException();
|
|
|
|
|
|
|
|
dao.SetContactLastModifedDate(contactId, lastModifedDate);
|
|
|
|
}
|
2021-02-24 16:50:07 +00:00
|
|
|
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2020-04-18 17:49:09 +00:00
|
|
|
private ContactPhotoManager.PhotoData UploadAvatar(int contactID, string imageUrl, bool uploadOnly, string tmpDirName, bool checkFormat = true)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
|
|
|
if (contactID != 0)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
return _contactPhotoManager.UploadPhoto(imageUrl, contactID, uploadOnly, checkFormat);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(tmpDirName) || tmpDirName == "null") tmpDirName = null;
|
2021-03-19 16:56:26 +00:00
|
|
|
return _contactPhotoManager.UploadPhotoToTemp(imageUrl, tmpDirName, checkFormat);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
private IEnumerable<ContactWithTaskDto> ToSimpleListContactDto(IReadOnlyList<Contact> itemList)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
if (itemList.Count == 0) return new List<ContactWithTaskDto>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
var result = new List<ContactWithTaskDto>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
var personsIDs = new List<int>();
|
|
|
|
var companyIDs = new List<int>();
|
|
|
|
var contactIDs = new int[itemList.Count];
|
|
|
|
|
|
|
|
var peopleCompanyIDs = new List<int>();
|
2021-03-09 15:37:16 +00:00
|
|
|
var peopleCompanyList = new Dictionary<int, ContactBaseDto>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var contactDao = _daoFactory.GetContactDao();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
for (var index = 0; index < itemList.Count; index++)
|
|
|
|
{
|
|
|
|
var contact = itemList[index];
|
|
|
|
|
|
|
|
if (contact is Company)
|
|
|
|
{
|
|
|
|
companyIDs.Add(contact.ID);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var person = contact as Person;
|
|
|
|
if (person != null)
|
|
|
|
{
|
|
|
|
personsIDs.Add(person.ID);
|
|
|
|
|
|
|
|
if (person.CompanyID > 0)
|
|
|
|
{
|
|
|
|
peopleCompanyIDs.Add(person.CompanyID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contactIDs[index] = itemList[index].ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (peopleCompanyIDs.Count > 0)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
var tmpList = contactDao.GetContacts(peopleCompanyIDs.ToArray()).ConvertAll(item => _mapper.Map<ContactBaseDto>(item));
|
2020-04-18 17:49:09 +00:00
|
|
|
var tmpListCanDelete = contactDao.CanDelete(tmpList.Select(item => item.Id).ToArray());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
foreach (var contactBaseDtoQuick in tmpList)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
contactBaseDtoQuick.CanDelete = contactBaseDtoQuick.CanEdit && tmpListCanDelete[contactBaseDtoQuick.Id];
|
|
|
|
peopleCompanyList.Add(contactBaseDtoQuick.Id, contactBaseDtoQuick);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
var contactInfos = new Dictionary<int, List<ContactInfoDto>>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
var addresses = new Dictionary<int, List<Address>>();
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
_daoFactory.GetContactInfoDao().GetAll(contactIDs).ForEach(
|
2020-04-16 19:41:37 +00:00
|
|
|
item =>
|
|
|
|
{
|
|
|
|
if (item.InfoType == ContactInfoType.Address)
|
|
|
|
{
|
|
|
|
if (!addresses.ContainsKey(item.ContactID))
|
|
|
|
{
|
|
|
|
addresses.Add(item.ContactID, new List<Address>
|
|
|
|
{
|
|
|
|
new Address(item)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addresses[item.ContactID].Add(new Address(item));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!contactInfos.ContainsKey(item.ContactID))
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
contactInfos.Add(item.ContactID, new List<ContactInfoDto> { _mapper.Map<ContactInfoDto>(item) });
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
contactInfos[item.ContactID].Add(_mapper.Map<ContactInfoDto>(item));
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var nearestTasks = _daoFactory.GetTaskDao().GetNearestTask(contactIDs.ToArray());
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
IEnumerable<TaskCategoryBaseDto> taskCategories = new List<TaskCategoryBaseDto>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (nearestTasks.Any())
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
taskCategories = _daoFactory.GetListItemDao().GetItems(ListType.TaskCategory).ConvertAll(item => _mapper.Map<TaskCategoryDto>(item));
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var contact in itemList)
|
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
ContactDto contactDto;
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
var person = contact as Person;
|
|
|
|
if (person != null)
|
|
|
|
{
|
|
|
|
var people = person;
|
|
|
|
|
2021-03-19 16:56:26 +00:00
|
|
|
var peopleDto = _mapper.Map<PersonDto>(people);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (people.CompanyID > 0 && peopleCompanyList.ContainsKey(people.CompanyID))
|
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
peopleDto.Company = peopleCompanyList[people.CompanyID];
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
contactDto = peopleDto;
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var company = contact as Company;
|
|
|
|
if (company != null)
|
|
|
|
{
|
2021-03-19 16:56:26 +00:00
|
|
|
contactDto = _mapper.Map<CompanyDto>(company);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new ArgumentException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
contactDto.CommonData = contactInfos.ContainsKey(contact.ID) ? contactInfos[contact.ID] : new List<ContactInfoDto>();
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
TaskBaseDto taskDto = null;
|
2020-04-16 19:41:37 +00:00
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
if (nearestTasks.ContainsKey(contactDto.Id))
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
var task = nearestTasks[contactDto.Id];
|
2020-04-22 20:46:49 +00:00
|
|
|
|
2021-03-17 11:50:13 +00:00
|
|
|
taskDto = _mapper.Map<TaskBaseDto>(task);
|
2020-04-16 19:41:37 +00:00
|
|
|
|
|
|
|
if (task.CategoryID > 0)
|
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
taskDto.Category = taskCategories.First(x => x.Id == task.CategoryID);
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 15:37:16 +00:00
|
|
|
result.Add(new ContactWithTaskDto
|
2021-02-24 16:50:07 +00:00
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
Contact = contactDto,
|
|
|
|
Task = taskDto
|
2021-02-24 16:50:07 +00:00
|
|
|
});
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region CanDelete for main contacts
|
|
|
|
|
|
|
|
if (result.Count > 0)
|
|
|
|
{
|
2020-04-18 17:49:09 +00:00
|
|
|
var resultListCanDelete = contactDao.CanDelete(result.Select(item => item.Contact.Id).ToArray());
|
2021-03-09 15:37:16 +00:00
|
|
|
foreach (var contactBaseDtoQuick in result)
|
2020-04-16 19:41:37 +00:00
|
|
|
{
|
2021-03-09 15:37:16 +00:00
|
|
|
contactBaseDtoQuick.Contact.CanDelete = contactBaseDtoQuick.Contact.CanEdit && resultListCanDelete[contactBaseDtoQuick.Contact.Id];
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2021-03-13 18:00:08 +00:00
|
|
|
}
|
2020-04-16 19:41:37 +00:00
|
|
|
}
|