<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Core.ApplicationServices;
using Core.ApplicationServices.Authorization;
using Core.ApplicationServices.Model.Result;
using Core.ApplicationServices.Model.System;
using Core.ApplicationServices.System;
using Core.DomainModel;
using Core.DomainModel.ItSystem;
using Core.DomainModel.Organization;
using Core.DomainServices;
using Core.DomainServices.Authorization;
using DocumentFormat.OpenXml.Office2010.Word;
using Newtonsoft.Json.Linq;
using Presentation.Web.Extensions;
using Presentation.Web.Infrastructure.Attributes;
using Presentation.Web.Models;
using Presentation.Web.Models.ItSystem;
using Swashbuckle.Swagger.Annotations;

namespace Presentation.Web.Controllers.API
{
    [PublicApi]
    public class ItSystemController : GenericHierarchyApiController<ItSystem, ItSystemDTO>
    {
        private readonly IGenericRepository<TaskRef> _taskRepository;
        private readonly IItSystemService _systemService;
        private readonly ReferenceService _referenceService;

        public ItSystemController(
            IGenericRepository<ItSystem> repository,
            IGenericRepository<TaskRef> taskRepository,
            IItSystemService systemService,
            ReferenceService referenceService,
            IAuthorizationContext authorizationContext)
            : base(repository, authorizationContext)
        {
            _taskRepository = taskRepository;
            _systemService = systemService;
            _referenceService = referenceService;
        }

        // DELETE api/T
        public override HttpResponseMessage Delete(int id, int organizationId)
        {
            var deleteResult = _systemService.Delete(id);
            switch (deleteResult)
            {
                case SystemDeleteResult.Forbidden:
                    return Forbidden();
                case SystemDeleteResult.InUse:
                    return Conflict(deleteResult);
                case SystemDeleteResult.HasChildren:
                    return Conflict(deleteResult);
                case SystemDeleteResult.HasExhibitInterfaces:
                    return Conflict(deleteResult);
                case SystemDeleteResult.UnknownError:
                    return Error("");
                case SystemDeleteResult.Ok:
                    return NoContent();
                default:
                    return Error("");
            }
        }

        private HttpResponseMessage Conflict(SystemDeleteResult systemDeleteResult)
        {
            return CreateResponse(HttpStatusCode.Conflict, systemDeleteResult, "");
        }

        protected override void DeleteQuery(ItSystem entity)
        {
            _systemService.Delete(entity.Id);<commit_msg>Backend done. Ready for frontend and tests<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Core.ApplicationServices;
using Core.ApplicationServices.Authorization;
using Core.ApplicationServices.Model.Result;
using Core.ApplicationServices.Model.System;
using Core.ApplicationServices.System;
using Core.DomainModel;
using Core.DomainModel.ItSystem;
using Core.DomainModel.Organization;
using Core.DomainServices;
using Core.DomainServices.Authorization;
using Newtonsoft.Json.Linq;
using Presentation.Web.Extensions;
using Presentation.Web.Infrastructure.Attributes;
using Presentation.Web.Models;
using Presentation.Web.Models.ItSystem;
using Swashbuckle.Swagger.Annotations;

namespace Presentation.Web.Controllers.API
{
    [PublicApi]
    public class ItSystemController : GenericHierarchyApiController<ItSystem, ItSystemDTO>
    {
        private readonly IGenericRepository<TaskRef> _taskRepository;
        private readonly IItSystemService _systemService;
        private readonly ReferenceService _referenceService;

        public ItSystemController(
            IGenericRepository<ItSystem> repository,
            IGenericRepository<TaskRef> taskRepository,
            IItSystemService systemService,
            ReferenceService referenceService,
            IAuthorizationContext authorizationContext)
            : base(repository, authorizationContext)
        {
            _taskRepository = taskRepository;
            _systemService = systemService;
            _referenceService = referenceService;
        }

        // DELETE api/T
        public override HttpResponseMessage Delete(int id, int organizationId)
        {
            var deleteResult = _systemService.Delete(id);
            switch (deleteResult)
            {
                case SystemDeleteResult.Forbidden:
                    return Forbidden();
                case SystemDeleteResult.InUse:
                    return Conflict(deleteResult);
                case SystemDeleteResult.HasChildren:
                    return Conflict(deleteResult);
                case SystemDeleteResult.HasExhibitInterfaces:
                    return Conflict(deleteResult);
                case SystemDeleteResult.UnknownError:
                    return Error("");
                case SystemDeleteResult.Ok:
                    return Ok();  // Correct response would be NoContent, but somewhere in the frontend this breaks causing a double delete on one request.
                                  // This means the request fails with 500 since the system is already delete in the first pass
                default:
                    return Error("");
            }
        }

        private HttpResponseMessage Conflict(SystemDeleteResult systemDeleteResult)
        {
            return CreateResponse(HttpStatusCode.Conflict, systemDeleteResult, "");
        }

        protected override void DeleteQuery(ItSystem entity)
        {
            _systemService.Delete(entity.Id);
{'fraction_non_alphanumeric': 0.0627006929187088, 'fraction_numerical': 0.0011830319418624302, 'mean_word_length': 2.5758308157099696, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2398854', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1327, 'n_words': 319}