C# Project & Developer Management Controller

Posted by [email protected] and classified in Computers

Written on in English with a size of 7.12 KB

C# Project and Developer Management Controller

This document outlines the core logic for a C# controller designed to manage software projects and their associated developers. It demonstrates fundamental operations such as adding, finding, and listing projects and developers, ensuring data integrity by preventing duplicates.

GestorController Class Definition

The GestorController class serves as the central hub for managing project and developer data. It resides within the GestionProyectos.Controllers namespace and utilizes models from GestionProyectos.Models.

using GestionProyectos.Models; //Controllers-GestionP

namespace GestionProyectos.Controllers
{
    public class GestorController
    {
        public static List Projects { get; set; };
    }
}

Static Constructor for Initialization

The static constructor ensures that the Projects list is initialized when the GestorController class is first accessed, providing a ready-to-use collection for project data.

static GestorController()
{
    Projects = new List(); List();
}

Note: The line new List(); List(); appears to have a redundant List(); call.

Project Management Operations

This section details methods for finding, checking existence, and adding projects to the system.

Find Project by Code

This method aims to locate a specific project within the Projects list using its unique codigo (code).

codigo )
{
    return Projects.Find(delegate (Project project) project.Codigo == codigo;
    });
}

Note: The method signature for FindProject is incomplete in the provided snippet. It would typically be public Project FindProject(int codigo).

Check Project Existence

Two overloaded methods are provided to verify if a project already exists, either by its codigo or by the Project object itself.

public bool ExistsProject(int codigo) (Project project) {
    return project.Codigo == codigo;
}
public bool ExistsProject(Project project)
{
    return ExistsProject(project.Codigo);
}

Note: The first ExistsProject method is syntactically incomplete; it likely intended to use Projects.Exists(delegate (Project project) { return project.Codigo == codigo; });.

Add New Project

This method attempts to register a new software development project. It prevents the addition of projects with duplicate codes.

public bool addProject(Project project)
( !ExistsProject(project.Codigo) )
{
    Projects.Add(project);
    return true;
};}

Note: The if condition syntax ( !ExistsProject(project.Codigo) ) is incomplete and should be enclosed in parentheses after if.

Developer Management Operations

This section covers methods related to finding, checking existence, and adding developers, both globally and within specific projects.

Find Developer by DNI

This method is intended to find a developer based on their DNI (identification number).

dni)
{
    return Developers.Find(delegate (Developer developer) developer.DNI == dni;
    });
}

Note: The method signature for FindDeveloper is incomplete. It would typically be public Developer FindDeveloper(string dni). Also, the Developers list is not explicitly defined in the provided class context.

Check Developer Existence

Multiple methods are available to check for a developer's existence:

  • ExistsDeveloper(int codigo, String dni): Checks if a developer exists within a specific project identified by its codigo.
  • IsRepeatedDeveloper(List developers, Developer developer): Checks if a developer is already present in a given list of developers.
  • ExistsDeveloper(List developers, String dni): Checks if a developer with a specific DNI exists in a given list of developers.
public bool ExistsDeveloper(int codigo, String dni)
{
    Project projectWanted = FindProject(codigo);
    if(projectWanted != null)
    {
        return ExistsDeveloper(projectWanted.Developers, dni);
    }
    return false;
}

public bool IsRepeatedDeveloper(List developers, Developer developer)
{
    return ExistsDeveloper(developers, developer.DNI);
}

public bool ExistsDeveloper(List developers, String dni)
{
    return developers.Exists(delegate (Developer developer) {
        return developer.DNI == dni;
    });
}
Add Developer to Project

These methods facilitate adding developers to projects, ensuring that developers are not added repeatedly to the same project.

public bool addDeveloper( Project project, Developer developer )
{
    if (!ExistsDeveloper(Developers, developer.DNI))
    {
        Developers.Add(developer);
    }
    if ( !ExistsDeveloper(project.Developers, developer.DNI) )
    {
        project.Developers.Add(developer);
        return true;
    }
    return false;
}

public bool addDeveloper(int codigo, Developer developer)
{
    if( ExistsProject(codigo) )
    {
        return addDeveloper(FindProject(codigo), developer);
    }
    return false;
}

Note: The first addDeveloper method references a global Developers list which is not defined in the provided class context.

Listing and Querying Developers and Projects

Methods for retrieving lists of developers within a project and identifying projects with the most developers.

List All Developers in a Project

This method returns a list of all developers participating in a project identified by its codigo.

public List FindAllDevelopers(int codigo)
{
    if(ExistsProject(codigo))
    {
        return FindProject(codigo).Developers;
    }
    return new List();
}

Note: The return type List is incomplete; it should be List<Developer> assuming Developer is the type.

Find Projects with Most Developers

This method identifies and returns a list of projects that have the highest number of participating developers.

public List FindProjectsMaxDevelopers()
{
    List projectsMax = new List();
    int current = 0, max = 0;
    foreach (Project project in Projects)
    {
        current = project.Developers.Count;
        if (current >= max)
        {
            if(current > max)
            {
                projectsMax.Clear();
                max = current;
            }
            projectsMax.Add(project);
        }
    }
    return projectsMax;
}

Note: The return type List is incomplete; it should be List<Project>.

This concludes the analysis of the GestorController logic for managing projects and developers.

Related entries: