Source

TrafficLight / src / Core / Presenters / EditProjectPresenter.cs

using RossCode.TrafficLight.Core.Domain;
using RossCode.TrafficLight.Core.Domain.Repositories;
using RossCode.TrafficLight.Core.Presenters.Views;
using RossCode.TrafficLight.Core.Services;

namespace RossCode.TrafficLight.Core.Presenters
{
    public class EditProjectPresenter : PresenterBase<IEditProjectView>
    {
        private readonly IProjectRepository projectRepository;
        private readonly IProjectStatusResolverService projectStatusResolverService;
        private Project project;

        public EditProjectPresenter(IEditProjectView view, IProjectRepository projectRepository, IProjectStatusResolverService projectStatusResolverService) : base(view)
        {
            this.projectRepository = projectRepository;
            this.projectStatusResolverService = projectStatusResolverService;
            View.SaveProject += SaveProject;
            view.TestProject += TestProject;
        }

        private void TestProject()
        {
            var testProject = new Project
                {
                    Name = View.ProjectName,
                    Url = View.ProjectUrl,
                    Username = View.Username,
                    Password = View.Password
                };

            var status = projectStatusResolverService.CheckStatus(testProject);
            View.Alert(status == BuildStatus.Unknown ? "Failure" : "Success");
        }

        private void SaveProject()
        {
            if (project == null)
            {
                project = new Project();
            }

            project.Name = View.ProjectName;
            project.Url = View.ProjectUrl;
            project.Username = View.Username;
            project.Password = View.Password;

            projectRepository.Save(project);

            View.Close();
        }

        public void SetProject(Project projectToEdit)
        {
            project = projectToEdit;
            View.SetupForProject(!project.Id.HasValue || project.Id.Value <= 0);
            View.ProjectName = project.Name;
            View.ProjectUrl = project.Url;
            View.Username = project.Username;
            View.Password = project.Password;
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.