Skip to content
Snippets Groups Projects
Sectors.cs 2 KiB
Newer Older
Michal Ondrejička's avatar
Michal Ondrejička committed
using SDK.Contracts.Communication;
using SDK.Exceptions;
using SDK.Models;
using System;
using System.Collections.Generic;
using System.Linq;
Michal Ondrejička's avatar
Michal Ondrejička committed
using System.Net.Http;
Michal Ondrejička's avatar
Michal Ondrejička committed
using System.Text;
using System.Threading.Tasks;

namespace tDevkit
{
Michal Ondrejička's avatar
Michal Ondrejička committed
    //(4/5)
Michal Ondrejička's avatar
Michal Ondrejička committed
    public partial class DevkitConnectorV3
    {
        public async Task<SectorContract[]> GetSectors()
        {
            string subUrl = Address.Sectors;
            var response = await GetRequest<SectorContract[]>(subUrl);

            return response;
        }
Michal Ondrejička's avatar
Michal Ondrejička committed
        public async Task<SectorContract> GetSector(int id)
        {
            string subUrl = Address.Sectors + id;
            var response = await GetRequest<SectorContract>(subUrl);

            return response;
        }
Michal Ondrejička's avatar
Michal Ondrejička committed
        public async Task<SectorContract> AddSector(SectorContract sectorContract)
        {
            string subUrl = Address.Sectors;
            var response = await PostRequest<AddSectorResponseContract>(subUrl, sectorContract);

            if (response.ErrorMessage != null)
                throw new ServerResponseException(ServerResponseException.message + " " + response.ErrorMessage);

            return (SectorContract)response;
        }
        public async Task<PatchResponseContract> UpdateSector(SectorContract sectorContract)
        {
            if (sectorContract.Id == 0)
            {
                throw new BadRequestException(NotFoundException.message + " Sector object has no Id.");
            }
            string subUrl = Address.Sectors + sectorContract.Id;
            var response = await PatchRequest(subUrl, sectorContract);

            if (response.ErrorMessage != null)
                throw new ServerResponseException(ServerResponseException.message + " " + response.ErrorMessage);

Michal Ondrejička's avatar
Michal Ondrejička committed
            return response;
        }
        public async Task<HttpResponseMessage> DeleteSector(int id)
        {
            string subUrl = Address.Sectors + id;
            var response = await DeleteRequest(subUrl);

Michal Ondrejička's avatar
Michal Ondrejička committed
            return response;
        }
    }
}