public IActionResult GetAll() { var userIdString = User.FindFirst(ClaimTypes.Name)?.Value; var userId = int.Parse(userIdString); var equipment = _equipmentRepository.GetAllEquipments(userId); return(Ok(equipment)); }
public override async Task <EquipmentsListResponse> GetAllEquipments(EquipmentsRequest request, ServerCallContext context) { var equipmentsFromDb = await _repo.GetAllEquipments(); var equipmentsListToReturn = _mapper.Map <List <EquipmentToReturn> >(equipmentsFromDb); var response = new EquipmentsListResponse(); foreach (var equipment in equipmentsListToReturn) { response.EquipmentList.Add(equipment); } return(response); }
public async Task <IActionResult> GetAllEquipments() { try { return(Json( new { Success = true, Data = JsonConvert.SerializeObject(await _equipmentRepository.GetAllEquipments()) })); } catch (Exception exception) { return(Json(new { Success = false, exception.Message })); } }
/// <summary> /// Get All Equipment Info /// </summary> /// <param name="search"></param> /// <returns></returns> public IResult GetAllEquipments(SearchSortModel search) { if (string.IsNullOrEmpty(search.SortColumn)) { search.SortColumn = Constants.CreatedDate; } var result = new Result { Operation = Operation.Read, Status = Status.Success }; try { var equipmentViewModels = new List <EquipmentViewModel>(); var equipments = _equipmentRepository.GetAllEquipments(search); if (equipments != null && equipments.Any()) { equipmentViewModels = equipments.Select(t => { var equipmentViewModel = new EquipmentViewModel(); equipmentViewModel.MapFromModel(t); if (t.TechnicalSpecifications == null || !t.TechnicalSpecifications.Any()) { return(equipmentViewModel); } var techSpecs = new List <TechSpecsViewModel>(); equipmentViewModel.TechnicalSpecifications = techSpecs.MapFromModel <TechnicalSpecification, TechSpecsViewModel>(t.TechnicalSpecifications); return(equipmentViewModel); }).ToList(); search.SearchResult = equipmentViewModels; } else { search.SearchResult = equipmentViewModels; result.Message = CommonErrorMessages.NoResultFound; } result.Body = search; } catch (Exception e) { result.Message = e.Message; result.Status = Status.Fail; } return(result); }
public void WillReturnEquipmentList() { //Arrange var testHelper = new TestHelper(); var testData = testHelper.CreateEquipmentList(); IEquipmentRepository eqRepository = Substitute.For <IEquipmentRepository>(); eqRepository.GetAllEquipments().Returns(testData); IUnitOfWork uow = Substitute.For <IUnitOfWork>(); uow.EquipmentRepository.Returns(eqRepository); EquipmentService eService = new EquipmentService(uow); //Act var equipments = eService.GetAllEquipments(); //Assert equipments.Should().NotBeNull(); }
public List <EquipmentDTO> GetAllEquipments() { return(_equipmentRepository.GetAllEquipments()); }