예제 #1
0
        public async Task <BaseResponse> Handle(command.AddClientCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var key    = _provider.GetAll().Result.Count() + 1;
                var client = new model.Client
                {
                    ClientId       = key.ToString(),
                    ClientName     = request.ClientName,
                    ClientLocation = request.ClientLocation
                };

                var response = await _provider.Add(client);

                return(new BaseResponse
                {
                    ResponseStatusCode = StatusCodes.Status201Created,
                    Value = response
                });
            }
            catch (Exception ex)
            {
                return(new BaseResponse
                {
                    ResponseStatusCode = StatusCodes.Status500InternalServerError,
                    Value = ex.Message
                });
            }
        }
예제 #2
0
        public async Task <BaseResponse> Handle(command.AddSkillCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var key   = _provider.GetAll().Result.Count() + 1;
                var skill = new model.Skills
                {
                    SkillId   = key.ToString(),
                    SkillName = request.SkillName
                };

                var response = await _provider.Add(skill);

                return(new BaseResponse
                {
                    ResponseStatusCode = StatusCodes.Status201Created,
                    Value = response
                });
            }
            catch (Exception ex)
            {
                return(new BaseResponse
                {
                    ResponseStatusCode = StatusCodes.Status500InternalServerError,
                    Value = ex
                });
            }
        }
예제 #3
0
        public async Task <BaseResponse> Handle(command.AddEmployeeCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var projectResponse = await _mediator.Send(new GetProjectByIdQuery { ProjectId = request.Project });

                if (projectResponse.ResponseStatusCode == StatusCodes.Status404NotFound)
                {
                    return(projectResponse);
                }

                var departmentResponse = await _mediator.Send(new GetDepartmentByIdQuery { DepartmentId = request.Department });

                if (departmentResponse.ResponseStatusCode == StatusCodes.Status404NotFound)
                {
                    return(departmentResponse);
                }

                var key = _provider.GetAll().Result.Count() + 1;
                var emp = new model.Employee
                {
                    EmployeeId  = key.ToString(),
                    Role        = request.Role,
                    FirstName   = request.FirstName,
                    LastName    = request.LastName,
                    DateOfBirth = request.DOB,
                    Billable    = request.Billable,
                    Project     = (model.Project)projectResponse.Value,
                    Department  = (model.Department)departmentResponse.Value
                };

                var response = await _provider.Add(emp);

                return(new BaseResponse
                {
                    ResponseStatusCode = StatusCodes.Status201Created,
                    Value = response
                });
            }
            catch (Exception ex)
            {
                return(new BaseResponse
                {
                    ResponseStatusCode = StatusCodes.Status500InternalServerError,
                    Value = ex.Message
                });
            }
        }
예제 #4
0
        public async Task <BaseResponse> Handle(query.GetAllDepartmentsQuery request, CancellationToken cancellationToken)
        {
            var departments = await _provider.GetAll();

            if (departments == null || !departments.Any())
            {
                return new BaseResponse
                       {
                           ResponseStatusCode = StatusCodes.Status404NotFound,
                           Value = "No Departments found"
                       }
            }
            ;
            return(new BaseResponse
            {
                ResponseStatusCode = StatusCodes.Status302Found,
                Value = departments
            });
        }
    }
예제 #5
0
        public async Task <BaseResponse> Handle(query.GetAllSkillsQuery request, CancellationToken cancellationToken)
        {
            var skills = await _provider.GetAll();

            if (skills == null || !skills.Any())
            {
                return new BaseResponse
                       {
                           ResponseStatusCode = StatusCodes.Status404NotFound,
                           Value = "No Skills found"
                       }
            }
            ;
            return(new BaseResponse
            {
                ResponseStatusCode = StatusCodes.Status302Found,
                Value = skills
            });
        }
    }
예제 #6
0
        public async Task <BaseResponse> Handle(command.AddProjectCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var client = await _mediator.Send(new GetClientByIdQuery { ClientId = request.ClientId });

                if (client.ResponseStatusCode == StatusCodes.Status404NotFound)
                {
                    return(client);
                }

                var key = _provider.GetAll().Result.Count() + 1;

                var project = new model.Project
                {
                    Id          = key.ToString(),
                    ProjectName = request.ProjectName,
                    ProjectType = request.ProjectType,
                    Client      = (model.Client)client.Value
                };

                var response = await _provider.Add(project);

                return(new BaseResponse
                {
                    ResponseStatusCode = StatusCodes.Status201Created,
                    Value = response
                });
            }
            catch (Exception ex)
            {
                return(new BaseResponse
                {
                    ResponseStatusCode = StatusCodes.Status500InternalServerError,
                    Value = ex
                });
            }
        }