public async Task <ActionResult <EquipmentRequestDto> > GetEquipmentRequest(Guid id)
        {
            EquipmentRequest request = await _logic.GetEquipmentRequestById(id);

            EquipmentRequestDto convertedRequest = _mapper.ConvertEquipmentRequestToEquipmentRequestDto(request);

            var token = await HttpContext.GetTokenAsync("access_token");

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var response = await httpClient.GetAsync($"api/Team/{request.TeamID}");

                string apiResponse = await response.Content.ReadAsStringAsync();

                var team = JsonConvert.DeserializeObject <TeamDto>(apiResponse);
                convertedRequest.Team = team;

                response = await httpClient.GetAsync($"api/User/{request.UserID}");

                apiResponse = await response.Content.ReadAsStringAsync();

                var user = JsonConvert.DeserializeObject <UserDto>(apiResponse);
                convertedRequest.User = user;

                EquipmentItem item = await _logic.GetEquipmentItemById(request.ItemId);

                convertedRequest.Item = item;
            }

            return(convertedRequest);
        }
예제 #2
0
        public EquipmentRequestDto ConvertEquipmentRequestToEquipmentRequestDto(EquipmentRequest equipment)
        {
            EquipmentRequestDto convertedRequest = new EquipmentRequestDto()
            {
                RequestID   = equipment.RequestID,
                UserID      = equipment.UserID,
                TeamID      = equipment.TeamID,
                RequestDate = equipment.RequestDate,
                Message     = equipment.Message,
                ItemId      = equipment.ItemId,
                Status      = equipment.Status
            };

            return(convertedRequest);
        }
예제 #3
0
        public async Task <IActionResult> CreateEquipmentAsync(
            [FromBody] EquipmentRequestDto createEquipmentRequestDto,
            CancellationToken token = default)
        {
            try
            {
                var equipmentServiceObject = Mapper.Map <EquipmentServiceObject>(createEquipmentRequestDto);
                var serviceResponse        = await _equipmentService.CreateEquipmentAsync(equipmentServiceObject, token);

                return(new CreatedResult(string.Empty, Mapper.Map <EquipmentResponseDto>(serviceResponse)));
            }
            catch (Exception ex)
            {
                return(new BadRequestResult());
            }
        }
예제 #4
0
        public async Task <IActionResult> UpdateEquipmentAsync(
            [FromRoute] int equipmentId,
            [FromBody] EquipmentRequestDto updateEquipmentRequestDto,
            CancellationToken token = default)
        {
            try
            {
                var equipmentServiceObject = Mapper.Map <EquipmentServiceObject>(updateEquipmentRequestDto);
                equipmentServiceObject.Id = equipmentId;
                var serviceResponse = await _equipmentService.UpdateEquipmentAsync(equipmentServiceObject, token);

                return(new OkObjectResult(Mapper.Map <EquipmentResponseDto>(serviceResponse)));
            }
            catch (Exception ex)
            {
                return(new BadRequestResult());
            }
        }
        public void ValidateEquipmentRequestDto()
        {
            var requestDto = new EquipmentRequestDto
            {
                RequestID   = Guid.NewGuid(),
                TeamID      = Guid.NewGuid(),
                User        = new UserDto(),
                UserID      = "fred",
                Team        = new TeamDto(),
                RequestDate = DateTime.Now,
                Message     = "i need equipment now!",
                Item        = new EquipmentItem(),
                ItemId      = 53,
                Status      = "Approved"
            };

            var results = ValidateModel(requestDto);

            Assert.True(results.Count == 0);
        }
        public async Task <IEnumerable <EquipmentRequestDto> > GetEquipmentRequests()
        {
            IEnumerable <EquipmentRequest> requests = await _logic.GetEquipmentRequests();

            List <EquipmentRequestDto> convertedRequests = new List <EquipmentRequestDto>();

            var token = await HttpContext.GetTokenAsync("access_token");

            using (var httpClient = new HttpClient()) {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                foreach (EquipmentRequest request in requests)
                {
                    EquipmentRequestDto convert = _mapper.ConvertEquipmentRequestToEquipmentRequestDto(request);
                    var response = await httpClient.GetAsync($"api/Team/{request.TeamID}");

                    string apiResponse = await response.Content.ReadAsStringAsync();

                    var team = JsonConvert.DeserializeObject <TeamDto>(apiResponse);
                    convert.Team = team;

                    response = await httpClient.GetAsync($"api/User/{request.UserID}");

                    apiResponse = await response.Content.ReadAsStringAsync();

                    var user = JsonConvert.DeserializeObject <UserDto>(apiResponse);
                    convert.User = user;

                    EquipmentItem item = await _logic.GetEquipmentItemById(request.ItemId);

                    convert.Item = item;
                    convertedRequests.Add(convert);
                }
            }

            // add logic to get user, team, item

            return(convertedRequests);
        }