mycorerepository/MyCore/Services/AutomationService.cs
2021-01-19 23:59:24 +01:00

38 lines
1.4 KiB
C#

using MyCore.Interfaces.DTO;
using MyCore.Interfaces.Models;
using MyCore.Services.MyControlPanel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MyCore.Service.Services
{
public class AutomationService
{
public static AutomationDTO CreateOrUpdate(AutomationDatabaseService _AutomationDatabaseService, string userId, AutomationCreateOrUpdateDetailDTO automationCreateOrUpdateDetailDTO, bool create)
{
Automation automation;
if (create)
automation = new Automation();
else
{
automation = _AutomationDatabaseService.GetById(automationCreateOrUpdateDetailDTO.Id);
}
automation.UserId = userId;
automation.Name = automationCreateOrUpdateDetailDTO.Name;
automation.CreatedDate = DateTime.Now;
automation.UpdatedDate = DateTime.Now;
automation.Triggers = automationCreateOrUpdateDetailDTO.Triggers;
automation.Conditions = automationCreateOrUpdateDetailDTO.Conditions;
automation.Actions = automationCreateOrUpdateDetailDTO.Actions;
if (create)
return _AutomationDatabaseService.Create(automation).ToDTO();
else
return _AutomationDatabaseService.Update(automation.Id, automation).ToDTO();
}
}
}