public async Task <List <GetIssueTicketResponse> > GetByStudent(int id) { var student = await _studentService.FindById(id); var issueTickets = await _repoWrapper.IssueTicket.FindAllAsyncWithCondition(i => i.OwnerId == id); //Check if issue ticket is found if (issueTickets == null || !issueTickets.Any()) { //Return null if no ticket is found; return(null); } var issueTicketTypes = (List <Param>) await _repoWrapper.Param.FindAllAsyncWithCondition( p => p.ParamTypeId == GlobalParams.ParamTypeIssueType); if (issueTicketTypes == null || !issueTicketTypes.Any()) { throw new HttpStatusCodeException(HttpStatusCode.NotFound, "IssueTicket: Types are not found."); } var result = new List <GetIssueTicketResponse>(); var types = await _paramService.FindAllParamEntitiesByParamType(GlobalParams.ParamTypeIssueType); foreach (var issueTicket in issueTickets) { var type = types.Find(t => t.ParamId == issueTicket.Type); Equipment equipment = null; if (issueTicket.EquipmentId != null) { equipment = await _repoWrapper.Equipment.FindByIdAsync(issueTicket.EquipmentId.Value); } Param equipmentType = null; Room room = null; if (equipment != null) { equipmentType = await _repoWrapper.Param.FindByIdAsync(equipment.EquipmentTypeId); if (equipment.RoomId != null) { room = await _repoWrapper.Room.FindByIdAsync(equipment.RoomId.Value); } } result.Add(GetIssueTicketResponse.ResponseFromEntity(issueTicket, student, type, equipment, equipmentType, room)); } return(result); }
public async Task <AdvancedGetRoomTransferResponse> AdvancedGetRoomTransfer(string sorts, string filters, int?page, int?pageSize) { var sieveModel = new SieveModel() { PageSize = pageSize, Sorts = sorts, Page = page, Filters = filters }; var roomTransfers = await _repoWrapper.RoomTransfer.FindAllAsync(); if (roomTransfers == null || roomTransfers.Any() == false) { //return null if no equipment is found return(new AdvancedGetRoomTransferResponse() { ResultList = null, CurrentPage = 1, TotalPage = 1 }); } var resultResponses = new List <GetRoomTransferResponse>(); var roomTypes = (List <Param>) await _paramService.FindAllParamEntitiesByParamType(GlobalParams.ParamTypeRoomType); foreach (var roomTransfer in roomTransfers) { var student = await _repoWrapper.Student.FindByIdAsync(roomTransfer.StudentId); Room room = null; if (roomTransfer.RoomId != null) { room = await _repoWrapper.Room.FindByIdAsync(roomTransfer.RoomId.Value); } resultResponses.Add(GetRoomTransferResponse.ResponseFromEntity(roomTransfer, student, room, roomTypes.Find(t => t.ParamId == roomTransfer.TargetRoomType))); } //Apply filter, sort var result = _sieveProcessor.Apply(sieveModel, resultResponses.AsQueryable(), applyPagination: false).ToList(); var response = new AdvancedGetRoomTransferResponse() { CurrentPage = page ?? 1, TotalPage = (int)Math.Ceiling((double)result.Count / pageSize ?? 1), //Apply pagination ResultList = _sieveProcessor .Apply(sieveModel, result.AsQueryable(), applyFiltering: false, applySorting: false).ToList() }; //Return List of result return(response); }