<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web.Http;
using Core.DomainModel;
using Core.DomainModel.ItProject;
using Core.DomainModel.ItSystem;
using Core.DomainServices;
using UI.MVC4.Models;

namespace UI.MVC4.Controllers.API
{
    public class ItProjectController : GenericHasRightsController<ItProject, ItProjectRight, ItProjectRole, ItProjectDTO>
    {
        private readonly IItProjectService _itProjectService;
        private readonly IGenericRepository<TaskRef> _taskRepository;
        private readonly IGenericRepository<ItSystemUsage> _itSystemUsageRepository;
        private readonly IGenericRepository<OrganizationUnit> _orgUnitRepository;

        //TODO: Man, this constructor smells ...
        public ItProjectController(IGenericRepository<ItProject> repository, IGenericRepository<ItProjectRight> rightRepository,
            IItProjectService itProjectService, IGenericRepository<OrganizationUnit> orgUnitRepository, IGenericRepository<TaskRef> taskRepository, 
            IGenericRepository<ItSystemUsage> itSystemUsageRepository) 
            : base(repository, rightRepository)
        {
            _itProjectService = itProjectService;
            _taskRepository = taskRepository;
            _itSystemUsageRepository = itSystemUsageRepository;
            _orgUnitRepository = orgUnitRepository;
        }

        public HttpResponseMessage GetByOrg([FromUri] int orgId)
        {
            try
            {
                var projects = _itProjectService.GetAll(orgId, includePublic: false).ToList();
                
                return Ok(Map(projects));
            }
            catch (Exception e)
            {
                return Error(e);
            }
        }

        public virtual HttpResponseMessage Get(string q, int orgId)
        {
            try
            {
                var items = Repository.Get(x => x.Name.Contains(q) && x.OrganizationId == orgId);

                return Ok(Map(items));
            }
            catch (Exception e)
            {
                return Error(e);
            }
        }

        public HttpResponseMessage GetCatalog(bool? catalog, [FromUri] int orgId)
        {
            try
            {
                //Get all projects inside the organizaton OR public
                var projects = _itProjectService.GetAll(orgId, includePublic: true);

                var dto = Map<IEnumerable<ItProject>, IEnumerable<ItProjectCatalogDTO>>(projects);

                return Ok(dto);
            }
            catch (Exception e)
            {
                return Error(e);
            }
        }

        //public HttpResponseMessage GetPrograms(string q, int orgId, bool? programs)
        //{
        //    try
        //    {
        //        var thePrograms = _itProjectService.GetPrograms(orgId, nameSearch: q);

        //        return Ok(Map(thePrograms));
        //    }
        //    catch (Exception e)
        //    {
        //        return Error(e);
        //    }
        //}

        //public HttpResponseMessage GetNonPrograms(string q, int orgId, bool? nonPrograms)
        //{
        //    try
        //    {
        //        var projects = _itProjectService.GetProjects(orgId, nameSearch: q);

        //        return Ok(Map(projects));
        //    }
        //    catch (Exception e)
        //    {
        //        return Error(e);
        //    }
        //}

        public HttpResponseMessage PostCloneProject(int id, bool? clone, [FromBody] ItProjectDTO dto)
        {
            try
            {
                //make sure we only clone projects that the is accessible from the organization
                var project = _itProjectService.GetAll(dto.OrganizationId).FirstOrDefault(p => p.Id == id);

                var clonedProject = _itProjectService.CloneProject(project, KitosUser, dto.OrganizationId);

                return Created(Map(clonedProject), new Uri(Request.RequestUri + "/" + clonedProject.Id));
            }
            catch (Exception e)
            {
                return Error(e);
            }
        }

        public HttpResponseMessage GetProjectsByCategory([FromUri] int orgId, [FromUri] int catId)
        {
            try
            {
                var projects = _itProjectService.GetAll(orgId, includePublic:false).Where(p => p.ItProjectCategoryId == catId);

                return Ok(Map(projects));
            }
            catch (Exception e)
            {
                return Error(e);<commit_msg>Removed commented out code<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web.Http;
using Core.DomainModel;
using Core.DomainModel.ItProject;
using Core.DomainModel.ItSystem;
using Core.DomainServices;
using UI.MVC4.Models;

namespace UI.MVC4.Controllers.API
{
    public class ItProjectController : GenericHasRightsController<ItProject, ItProjectRight, ItProjectRole, ItProjectDTO>
    {
        private readonly IItProjectService _itProjectService;
        private readonly IGenericRepository<TaskRef> _taskRepository;
        private readonly IGenericRepository<ItSystemUsage> _itSystemUsageRepository;
        private readonly IGenericRepository<OrganizationUnit> _orgUnitRepository;

        //TODO: Man, this constructor smells ...
        public ItProjectController(IGenericRepository<ItProject> repository, IGenericRepository<ItProjectRight> rightRepository,
            IItProjectService itProjectService, IGenericRepository<OrganizationUnit> orgUnitRepository, IGenericRepository<TaskRef> taskRepository, 
            IGenericRepository<ItSystemUsage> itSystemUsageRepository) 
            : base(repository, rightRepository)
        {
            _itProjectService = itProjectService;
            _taskRepository = taskRepository;
            _itSystemUsageRepository = itSystemUsageRepository;
            _orgUnitRepository = orgUnitRepository;
        }

        public HttpResponseMessage GetByOrg([FromUri] int orgId)
        {
            try
            {
                var projects = _itProjectService.GetAll(orgId, includePublic: false).ToList();
                
                return Ok(Map(projects));
            }
            catch (Exception e)
            {
                return Error(e);
            }
        }

        public virtual HttpResponseMessage Get(string q, int orgId)
        {
            try
            {
                var items = Repository.Get(x => x.Name.Contains(q) && x.OrganizationId == orgId);

                return Ok(Map(items));
            }
            catch (Exception e)
            {
                return Error(e);
            }
        }

        public HttpResponseMessage GetCatalog(bool? catalog, [FromUri] int orgId)
        {
            try
            {
                //Get all projects inside the organizaton OR public
                var projects = _itProjectService.GetAll(orgId, includePublic: true);

                var dto = Map<IEnumerable<ItProject>, IEnumerable<ItProjectCatalogDTO>>(projects);

                return Ok(dto);
            }
            catch (Exception e)
            {
                return Error(e);
            }
        }

        public HttpResponseMessage PostCloneProject(int id, bool? clone, [FromBody] ItProjectDTO dto)
        {
            try
            {
                //make sure we only clone projects that the is accessible from the organization
                var project = _itProjectService.GetAll(dto.OrganizationId).FirstOrDefault(p => p.Id == id);

                var clonedProject = _itProjectService.CloneProject(project, KitosUser, dto.OrganizationId);

                return Created(Map(clonedProject), new Uri(Request.RequestUri + "/" + clonedProject.Id));
            }
            catch (Exception e)
            {
                return Error(e);
            }
        }

        public HttpResponseMessage GetProjectsByCategory([FromUri] int orgId, [FromUri] int catId)
        {
            try
            {
                var projects = _itProjectService.GetAll(orgId, includePublic:false).Where(p => p.ItProjectCategoryId == catId);

                return Ok(Map(projects));
            }
            catch (Exception e)
            {
                return Error(e);
{'fraction_non_alphanumeric': 0.08085157277837579, 'fraction_numerical': 0.00047841167324482717, 'mean_word_length': 1.8578263841421736, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1451569', 'n_tokens_mistral': 2120, 'n_tokens_neox': 2059, 'n_words': 462}