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
{
///
/// Service der das Melden von Feedback an gehgassi ermöglicht
///
public class FeedbackService : ServiceBase, IFeedbackService
{
private readonly ICommunicationService _communicationService;
///
/// Erstellt eine Instanz
///
/// Instanz eines IUnitOfWork
/// Instanz eines ICommunicationService
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 GetAsync(object id, bool noTracking = true)
{
await Task.Delay(1);
throw new NotImplementedException();
}
///
/// Erstellen eines Feedbacks
///
///
public AppFeedback Create()
{
var feedback = new AppFeedback();
return feedback;
}
///
/// Anlegen eines Feedbacks
///
/// AppFeedback
/// Aktuelles Accesstoken
/// CancellationToken
/// Angelegter Walk oder null, wenn nicht erfolgreich
public async Task 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;
}
}
}