Софтуерно Инженерство
Loading...
SvetoslavPorozhanov avatar SvetoslavPorozhanov 4 Точки

7. Employees and Projects и 11. Find Latest 10 Projects

Здравейте,

Условия: https://judge.softuni.bg/Contests/Compete/Index/351#0

Решение на 7-ма: https://pastebin.com/V0Ri9QAm

Решение на 11-та: https://pastebin.com/sChWFGwH

И двете задачи ми работят локално, но ми гърмат в Judge. На 11-та е объркан примера.

Тагове:
krasizorbov avatar krasizorbov 142 Точки

Ето 7-ма:

using SoftUni.Data;
using System;
using System.Linq;
using System.Text;

namespace P07_EmployeesAndProjects
{
    public class Program
    {
        static void Main(string[] args)
        {
            SoftUniContext context = new SoftUniContext();

            using (context)
            {
                var result = GetEmployeesInPeriod(context);

                Console.WriteLine(result);
            }
        }
        public static string GetEmployeesInPeriod(SoftUniContext context)
        {
            var employees = context.Employees.Where(e => e.EmployeesProjects.Any(ep => ep.Project.StartDate.Year >= 2001 && ep.Project.StartDate.Year <= 2003))
                .Select(e => new
                {
                    FirstName = e.FirstName,
                    LastName = e.LastName,
                    ManagerFirstName = e.Manager.FirstName,
                    ManagerLastName = e.Manager.LastName,
                    Projects = e.EmployeesProjects.Select(ep => new
                    {
                        ProjectName = ep.Project.Name,
                        ProjectStartDate = ep.Project.StartDate,
                        ProjectEndDate = ep.Project.EndDate
                    })
                }).Take(10);

            StringBuilder employeeManagerResult = new StringBuilder();

            foreach (var employee in employees)
            {
                employeeManagerResult.AppendLine($"{employee.FirstName} {employee.LastName} - Manager: {employee.ManagerFirstName} {employee.ManagerLastName}");

                foreach (var project in employee.Projects)
                {
                    var startDate = project.ProjectStartDate.ToString("M/d/yyyy h:mm:ss tt");
                    var endDate = project.ProjectEndDate.HasValue ? project.ProjectEndDate.Value.ToString("M/d/yyyy h:mm:ss tt") : "not finished";

                    employeeManagerResult.AppendLine($"--{project.ProjectName} - {startDate} - {endDate}");
                }
            }
            return employeeManagerResult.ToString().TrimEnd();
        }
    }
}

0
krasizorbov avatar krasizorbov 142 Точки

И 11-та:

using SoftUni.Data;
using System;
using System.Linq;
using System.Text;

namespace P11_FindLatest10Projects
{
    public class Program
    {
        static void Main(string[] args)
        {
            SoftUniContext context = new SoftUniContext();

            using (context)
            {
                string result = GetLatestProjects(context);
                Console.WriteLine(result);
            }
        }
        public static string GetLatestProjects(SoftUniContext context)
        {
            StringBuilder result = new StringBuilder();

            var projects = context.Projects.OrderByDescending(p => p.StartDate).Take(10).Select(s => new
            {
                ProjectName = s.Name,
                ProjectDescription = s.Description,
                ProjectStartDate = s.StartDate
            }).OrderBy(n => n.ProjectName).ToArray();

            foreach (var p in projects)
            {
                var startDate = p.ProjectStartDate.ToString("M/d/yyyy h:mm:ss tt");
                result.AppendLine($"{p.ProjectName}");
                result.AppendLine($"{p.ProjectDescription}");
                result.AppendLine($"{startDate}");
            }
            return result.ToString().TrimEnd();
        }
    }
}

0