Esempio n. 1
0
        public async Task <BaseResponse> Handle(command.ModifyProjectCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var projects = await _provider.GetSpecificById(request.ProjectId);

                if (projects == null || !projects.Any())
                {
                    return new BaseResponse
                           {
                               ResponseStatusCode = StatusCodes.Status404NotFound,
                               Value = "Project not found"
                           }
                }
                ;

                var project = new model.Project
                {
                    Id          = request.ProjectId.ToString(),
                    ProjectName = request.ProjectType
                };

                var response = await _provider.Update(project);

                return(new BaseResponse
                {
                    ResponseStatusCode = StatusCodes.Status200OK,
                    Value = response
                });
            }
            catch (Exception ex)
            {
                return(new BaseResponse
                {
                    ResponseStatusCode = StatusCodes.Status500InternalServerError,
                    Value = ex
                });
            }
        }
Esempio n. 2
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
                });
            }
        }