76 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using gehGassiApp.Core.Data;
using gehGassiApp.Core.Interfaces;
using gehGassiApp.Core.Mapper;
using gehGassiApp.Domain.Common;
using gehGassiApp.Domain.Feedback;
namespace gehGassiApp.Core.Services
{
/// <summary>
/// Service der das Melden von Feedback an gehgassi ermöglicht
/// </summary>
public class FeedbackService : ServiceBase<AppFeedback>, IFeedbackService
{
private readonly ICommunicationService _communicationService;
/// <summary>
/// Erstellt eine Instanz
/// </summary>
/// <param name="unitOfWork">Instanz eines IUnitOfWork</param>
/// <param name="communicationService">Instanz eines ICommunicationService</param>
public FeedbackService(IUnitOfWork unitOfWork, ICommunicationService communicationService) : base(unitOfWork)
{
_communicationService = communicationService;
}
public override AppFeedback Get(object id, bool noTracking = true)
{
throw new NotImplementedException();
}
public override async Task<AppFeedback> GetAsync(object id, bool noTracking = true)
{
await Task.Delay(1);
throw new NotImplementedException();
}
/// <summary>
/// Erstellen eines Feedbacks
/// </summary>
/// <returns></returns>
public AppFeedback Create()
{
var feedback = new AppFeedback();
return feedback;
}
/// <summary>
/// Anlegen eines Feedbacks
/// </summary>
/// <param name="feedback">AppFeedback</param>
/// <param name="accessToken">Aktuelles Accesstoken</param>
/// <param name="token">CancellationToken</param>
/// <returns>Angelegter Walk oder null, wenn nicht erfolgreich</returns>
public async Task<AppFeedback> CreateAsync(AppFeedback feedback, string accessToken, CancellationToken token)
{
var isConnected = await _communicationService.IsConnected();
if (isConnected)
{
var dto = feedback.ToCreateDto();
var createResult = await _communicationService.CreateFeedbackAsync(dto, accessToken, token);
if (createResult.Success && createResult.Value.Status == CreateStatus.Success)
{
return createResult.Value.Value;
}
}
return null;
}
}
}