Пример #1
0
        private async Task <int> UpdateAnOpeningPosition(SqlConnection connection, OpeningPositionsSummary opening, int projectId)
        {
            var sql = @"
                UPDATE Positions 
                SET
                    DisciplineId = (SELECT Id FROM Disciplines WHERE Name = @DisciplineName),
                    ProjectId = @ProjectId,
                    ProjectedMonthlyHours = @ProjectedMonthlyHours,
                    ResourceId = NULL,
                    YearsOfExperience = @YearsOfExperience,
                    IsConfirmed = 0
                WHERE
                    Id = @PositionId
            ;";

            var hours = JsonConvert.SerializeObject(opening.CommitmentMonthlyHours);

            connection.Open();
            int success = await connection.ExecuteAsync(sql, new
            {
                DisciplineName        = opening.Discipline,
                ProjectId             = projectId,
                ProjectedMonthlyHours = hours,
                YearsOfExperience     = opening.YearsOfExp,
                PositionId            = opening.PositionID
            });

            connection.Close();

            return(success);
        }
Пример #2
0
        private async Task <int> CreateAnOpeningPosition(SqlConnection connection, OpeningPositionsSummary opening, int projectId)
        {
            var sql = @"
                INSERT INTO Positions
                    ([DisciplineId], [ProjectId], [ProjectedMonthlyHours], [ResourceId], [PositionName], [YearsOfExperience], [IsConfirmed])
                VALUES
                    (
                        (SELECT Id FROM Disciplines WHERE Name = @DisciplineName),
                        @ProjectId, @ProjectedMonthlyHours,
                        NULL, NULL, @YearsOfExperience, 0
                    );
                SELECT CAST(scope_identity() as int);
            ;";

            string hours = JsonConvert.SerializeObject(opening.CommitmentMonthlyHours);

            connection.Open();
            var id = await connection.QuerySingleAsync <int>(sql, new
            {
                DisciplineName        = opening.Discipline,
                ProjectId             = projectId,
                ProjectedMonthlyHours = hours,
                YearsOfExperience     = opening.YearsOfExp,
            });

            connection.Close();

            return(id);
        }
        private static IEnumerable <OpeningPositionsSummary> GetOpenings(string discipline, HashSet <string> skills)
        {
            var opening = new OpeningPositionsSummary
            {
                PositionID             = 0,
                CommitmentMonthlyHours = new Dictionary <string, int> {
                    ["2020-05-01"] = 5
                },
                Discipline = discipline,
                YearsOfExp = "1-3",
                Skills     = skills
            };

            return(Enumerable.Empty <OpeningPositionsSummary>().Append(opening));
        }
Пример #4
0
        public async Task <IActionResult> UnassignResource([FromRoute] int openingId)
        {
            if (openingId == 0)
            {
                var error = new BadRequestException($"The given opening {openingId} is invalid");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }
            try
            {
                Position position = await positionsRepository.GetAPosition(openingId);

                if (position.ResourceId == null)
                {
                    var error = new BadRequestException($"Position does not have a resource to unassign");
                    return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
                }

                User user = await usersRepository.GetAUser(position.ResourceId);

                if (position == null)
                {
                    var error = new NotFoundException($"Invalid positionId {openingId}.");
                    return(StatusCode(StatusCodes.Status404NotFound, new CustomException <NotFoundException>(error).GetException()));
                }
                if (user == null)
                {
                    var error = new NotFoundException($"Resource with id {position.ResourceId} not found.");
                    return(StatusCode(StatusCodes.Status404NotFound, new CustomException <NotFoundException>(error).GetException()));
                }
                position.ResourceId  = null;
                position.IsConfirmed = false;

                position = await positionsRepository.UpdateAPosition(position);

                IEnumerable <Position> positions = await positionsRepository.GetAllPositionsOfUser(user.Id);

                IEnumerable <OutOfOffice> outOfOffices = await outOfOfficeRepository.GetAllOutOfOfficeForUser(user.Id);

                int newUtilizationOfUser = await utilizationRepository.CalculateUtilizationOfUser(positions, outOfOffices);

                user = await usersRepository.UpdateUtilizationOfUser(newUtilizationOfUser, user.Id);

                OpeningPositionsResource openingRes = await positionsRepository.GetAnOpeningPositionsResource(openingId);

                OpeningPositionsSummary openingSummary = mapper.Map <OpeningPositionsResource, OpeningPositionsSummary>(openingRes);
                RequestUnassign         response       = new RequestUnassign {
                    OpeningId            = position.Id,
                    UserId               = user.Id,
                    ConfirmedUtilization = user.Utilization,
                    Opening              = openingSummary
                };


                return(StatusCode(StatusCodes.Status200OK, response));
            }
            catch (Exception err)
            {
                var errMessage = $"Source: {err.Source}\n  Message: {err.Message}\n  StackTrace: {err.StackTrace}\n";
                if (err is SqlException)
                {
                    var error = new InternalServerException(errMessage);
                    return(StatusCode(StatusCodes.Status500InternalServerError, new CustomException <InternalServerException>(error).GetException()));
                }
                else
                {
                    var error = new BadRequestException(errMessage);
                    return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
                }
            }
        }