示例#1
0
        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);
        }
示例#2
0
        public async Task <AdvancedGetIssueTicketResponse> AdvancedGetIssueTicket(string sorts, string filters, int?page, int?pageSize)
        {
            //Build model for SieveProcessor
            var sieveModel = new SieveModel()
            {
                PageSize = pageSize,
                Sorts    = sorts,
                Page     = page,
                Filters  = filters
            };

            //Get all IssueTickets
            var issueTickets = await _repoWrapper.IssueTicket.FindAllAsync();

            if (issueTickets == null || issueTickets.Any() == false)
            {
                return(new AdvancedGetIssueTicketResponse()
                {
                    ResultList = null,
                    CurrentPage = 1,
                    TotalPage = 1
                });
            }

            var resultResponses = new List <GetIssueTicketResponse>();
            var types           = await _paramService.FindAllParamEntitiesByParamType(GlobalParams.ParamTypeIssueType);

            foreach (var issueTicket in issueTickets)
            {
                var type = types.Find(t => t.ParamId == issueTicket.Type);

                var owner = await _repoWrapper.Student.FindByIdAsync(issueTicket.OwnerId);

                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);
                    }
                }

                resultResponses.Add(GetIssueTicketResponse.ResponseFromEntity(issueTicket, owner, type, equipment, equipmentType, room));
            }

            //Apply filter, sort
            var result = _sieveProcessor.Apply(sieveModel, resultResponses.AsQueryable(), applyPagination: false).ToList();

            var response = new AdvancedGetIssueTicketResponse()
            {
                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);
        }