DocSpace-client/products/ASC.CRM/Server/ApiModels/RelationshipEventDto.cs

236 lines
8.1 KiB
C#
Raw Normal View History

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.
*
*/
using ASC.Api.Core;
using ASC.Api.Documents;
using ASC.Common;
using ASC.CRM.Core;
2020-04-18 17:49:09 +00:00
using ASC.CRM.Core.Dao;
2020-04-16 19:41:37 +00:00
using ASC.CRM.Core.Entities;
2020-04-22 20:46:49 +00:00
using ASC.CRM.Core.Enums;
2020-04-16 19:41:37 +00:00
using ASC.Web.Api.Models;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
2021-03-09 15:37:16 +00:00
namespace ASC.CRM.ApiModels
2020-04-16 19:41:37 +00:00
{
[DataContract(Name = "entity", Namespace = "")]
2021-03-09 15:37:16 +00:00
public class EntityDto
2020-04-16 19:41:37 +00:00
{
[DataMember]
public String EntityType { get; set; }
[DataMember]
public int EntityId { get; set; }
[DataMember]
public String EntityTitle { get; set; }
2021-03-09 15:37:16 +00:00
public static EntityDto GetSample()
2020-04-16 19:41:37 +00:00
{
2021-03-09 15:37:16 +00:00
return new EntityDto
2020-04-16 19:41:37 +00:00
{
EntityId = 123445,
EntityType = "opportunity",
EntityTitle = "Household appliances internet shop"
};
}
}
2021-03-01 17:36:18 +00:00
[Scope]
2021-03-09 15:37:16 +00:00
public class EntityDtoHelper
2020-04-22 20:46:49 +00:00
{
2021-03-09 15:37:16 +00:00
public EntityDtoHelper(DaoFactory daoFactory)
2020-04-22 20:46:49 +00:00
{
DaoFactory = daoFactory;
}
public DaoFactory DaoFactory { get; }
2021-03-09 15:37:16 +00:00
public EntityDto Get(EntityType entityType, int entityID)
2020-04-22 20:46:49 +00:00
{
if (entityID == 0) return null;
2021-03-09 15:37:16 +00:00
var result = new EntityDto
2020-04-22 20:46:49 +00:00
{
EntityId = entityID
};
switch (entityType)
{
case EntityType.Case:
var caseObj = DaoFactory.GetCasesDao().GetByID(entityID);
if (caseObj == null)
return null;
result.EntityType = "case";
result.EntityTitle = caseObj.Title;
break;
case EntityType.Opportunity:
var dealObj = DaoFactory.GetDealDao().GetByID(entityID);
if (dealObj == null)
return null;
result.EntityType = "opportunity";
result.EntityTitle = dealObj.Title;
break;
default:
return null;
}
return result;
}
}
2020-04-16 19:41:37 +00:00
[DataContract(Name = "historyEvent", Namespace = "")]
2021-03-09 15:37:16 +00:00
public class RelationshipEventDto
2020-04-16 19:41:37 +00:00
{
2021-03-09 15:37:16 +00:00
public RelationshipEventDto()
2020-04-16 19:41:37 +00:00
{
}
[DataMember(Name = "id")]
public int Id { get; set; }
2021-03-09 15:37:16 +00:00
2020-04-16 19:41:37 +00:00
public EmployeeWraper CreateBy { get; set; }
[DataMember(IsRequired = true, EmitDefaultValue = false)]
public ApiDateTime Created { get; set; }
[DataMember(IsRequired = true, EmitDefaultValue = false)]
public String Content { get; set; }
[DataMember(IsRequired = true, EmitDefaultValue = false)]
2021-03-09 15:37:16 +00:00
public HistoryCategoryBaseDto Category { get; set; }
2020-04-16 19:41:37 +00:00
2021-03-09 15:37:16 +00:00
public ContactBaseDto Contact { get; set; }
2020-04-16 19:41:37 +00:00
[DataMember]
2021-03-09 15:37:16 +00:00
public EntityDto Entity { get; set; }
2020-04-16 19:41:37 +00:00
2021-03-09 15:37:16 +00:00
2020-04-16 19:41:37 +00:00
public bool CanEdit { get; set; }
2021-03-09 15:37:16 +00:00
2020-04-16 19:41:37 +00:00
public IEnumerable<FileWrapper<int>> Files { get; set; }
2021-03-09 15:37:16 +00:00
public static RelationshipEventDto GetSample()
2020-04-16 19:41:37 +00:00
{
2021-03-09 15:37:16 +00:00
return new RelationshipEventDto
2020-04-16 19:41:37 +00:00
{
CanEdit = true,
2021-03-09 15:37:16 +00:00
Category = HistoryCategoryBaseDto.GetSample(),
Entity = EntityDto.GetSample(),
Contact = ContactBaseDto.GetSample(),
2020-04-16 19:41:37 +00:00
Created = ApiDateTime.GetSample(),
CreateBy = EmployeeWraper.GetSample(),
Files = new[] { FileWrapper<int>.GetSample() },
Content = @"Agreed to meet at lunch and discuss the client commercial offer"
};
}
}
2021-03-01 17:36:18 +00:00
[Scope]
2021-03-09 15:37:16 +00:00
public class RelationshipEventDtoHelper
2020-04-16 19:41:37 +00:00
{
2021-03-09 15:37:16 +00:00
public RelationshipEventDtoHelper(
2020-04-18 17:49:09 +00:00
ApiDateTimeHelper apiDateTimeHelper,
2020-04-16 19:41:37 +00:00
EmployeeWraperHelper employeeWraperHelper,
2021-03-09 15:37:16 +00:00
ContactDtoHelper contactBaseDtoHelper,
2020-04-18 17:49:09 +00:00
FileWrapperHelper fileWrapperHelper,
CRMSecurity cRMSecurity,
2020-04-22 20:46:49 +00:00
DaoFactory daoFactory,
2021-03-09 15:37:16 +00:00
EntityDtoHelper entityDtoHelper,
HistoryCategoryDtoHelper historyCategoryDtoHelper)
2020-04-16 19:41:37 +00:00
{
ApiDateTimeHelper = apiDateTimeHelper;
EmployeeWraperHelper = employeeWraperHelper;
CRMSecurity = cRMSecurity;
2020-04-18 17:49:09 +00:00
DaoFactory = daoFactory;
2021-03-09 15:37:16 +00:00
ContactBaseDtoHelper = contactBaseDtoHelper;
2020-04-18 17:49:09 +00:00
FileWrapperHelper = fileWrapperHelper;
2021-03-09 15:37:16 +00:00
EntityDtoHelper = entityDtoHelper;
HistoryCategoryDtoHelper = historyCategoryDtoHelper;
2020-04-16 19:41:37 +00:00
}
2021-03-09 15:37:16 +00:00
public HistoryCategoryDtoHelper HistoryCategoryDtoHelper { get; }
2020-04-18 17:49:09 +00:00
public FileWrapperHelper FileWrapperHelper { get; }
2021-03-09 15:37:16 +00:00
public ContactDtoHelper ContactBaseDtoHelper { get; }
2020-04-18 17:49:09 +00:00
public DaoFactory DaoFactory { get; }
2020-04-16 19:41:37 +00:00
public CRMSecurity CRMSecurity { get; }
public ApiDateTimeHelper ApiDateTimeHelper { get; }
public EmployeeWraperHelper EmployeeWraperHelper { get; }
2021-03-09 15:37:16 +00:00
public EntityDtoHelper EntityDtoHelper { get; }
public RelationshipEventDto Get(RelationshipEvent relationshipEvent)
2020-04-16 19:41:37 +00:00
{
2021-03-09 15:37:16 +00:00
var result = new RelationshipEventDto
2020-04-16 19:41:37 +00:00
{
Id = relationshipEvent.ID,
CreateBy = EmployeeWraperHelper.Get(relationshipEvent.CreateBy),
Created = ApiDateTimeHelper.Get(relationshipEvent.CreateOn),
Content = relationshipEvent.Content,
Files = new List<FileWrapper<int>>(),
CanEdit = CRMSecurity.CanEdit(relationshipEvent)
};
2020-04-18 17:49:09 +00:00
var historyCategory = DaoFactory.GetListItemDao().GetByID(relationshipEvent.CategoryID);
if (historyCategory != null)
{
2021-03-09 15:37:16 +00:00
result.Category = HistoryCategoryDtoHelper.Get(historyCategory);
2020-04-18 17:49:09 +00:00
}
if (relationshipEvent.EntityID > 0)
{
2021-03-09 15:37:16 +00:00
result.Entity = EntityDtoHelper.Get(relationshipEvent.EntityType, relationshipEvent.EntityID);
2020-04-18 17:49:09 +00:00
}
result.Files = DaoFactory.GetRelationshipEventDao().GetFiles(relationshipEvent.ID).ConvertAll(file => FileWrapperHelper.Get<int>(file));
if (relationshipEvent.ContactID > 0)
{
var relativeContact = DaoFactory.GetContactDao().GetByID(relationshipEvent.ContactID);
if (relativeContact != null)
{
2021-03-09 15:37:16 +00:00
result.Contact = ContactBaseDtoHelper.GetContactBaseDto(relativeContact);
2020-04-18 17:49:09 +00:00
}
}
result.CanEdit = CRMSecurity.CanAccessTo(relationshipEvent);
return result;
2020-04-16 19:41:37 +00:00
}
}
}