예제 #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.ModifyClientCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var clients = await _provider.GetSpecificById(request.ClientId);

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

                var client = new model.Client
                {
                    ClientId       = request.ClientId.ToString(),
                    ClientName     = request.ClientName,
                    ClientLocation = request.ClientLocation
                };

                var response = await _provider.Update(client);

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