practicekea_backend/microservices/_layers/common/CalendarService.cs

73 lines
2.2 KiB
C#
Raw Permalink Normal View History

2025-10-22 13:05:31 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
public class CalendarService
{
private readonly OdooService _odooService;
public CalendarService(OdooService odooService)
{
_odooService = odooService ?? throw new ArgumentNullException(nameof(odooService));
}
/// <summary>
/// Creates a calendar event.
/// </summary>
/// <param name="eventData">The event data to create.</param>
/// <returns>ID of the created event.</returns>
public async Task<int> CreateEventAsync(object eventData)
{
if (eventData == null)
{
throw new ArgumentNullException(nameof(eventData), "Event data cannot be null.");
}
return await _odooService.CreateAsync("calendar.event", eventData);
}
/// <summary>
/// Deletes a calendar event based on event ID.
/// </summary>
/// <param name="eventId">The ID of the event to delete.</param>
/// <returns>True if deleted successfully, otherwise false.</returns>
public async Task<bool> DeleteEventAsync(int eventId)
{
return await _odooService.DeleteAsync("calendar.event", eventId);
}
public async Task<List<object>> GetEventsAsync(object filterData)
{
string[] fields = { "id", "name", "start", "stop", "user_id", "partner_ids" };
return await _odooService.SearchAsync("calendar.event", filterData, fields);
}
/// <summary>
/// Updates an existing calendar event.
/// </summary>
/// <param name="eventId">The ID of the event to update.</param>
/// <param name="updateData">The data to update.</param>
/// <returns>True if the update was successful, otherwise false.</returns>
public async Task<bool> UpdateMeetingAsync(int eventId, Dictionary<string, object> updateData)
{
if (eventId <= 0)
{
throw new ArgumentException("Invalid event ID.", nameof(eventId));
}
if (updateData == null || updateData.Count == 0)
{
throw new ArgumentNullException(nameof(updateData), "Update data cannot be null or empty.");
}
return await _odooService.UpdateAsync("calendar.event", eventId, updateData);
}
}