public IActionResult GetTicketType(Guid id)
        {
            try
            {
                var TicketType = _ITicketTypeService.GetAllTicketType(_ => _.Id == id, _ => _.Atrraction, _ => _.Atrraction.City).FirstOrDefault();

                if (TicketType == null)
                {
                    return(NotFound());
                }
                var result = _mapper.Map <TicketTypeDetailVM>(TicketType);
                return(Ok(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Beispiel #2
0
 public IActionResult GetPass(Guid id)
 {
     try
     {
         var pass = _iPassService.GetAllPass(_ => _.Id == id, _ => _.Collections).FirstOrDefault();
         if (pass == null)
         {
             return(NotFound());
         }
         var result = _mapper.Map <PassVM>(pass);
         result.Collections = new List <CollectionVM>();
         pass.Collections.ToList().ForEach(_ =>
         {
             var collection              = _iCollectionService.GetAllCollection(v => v.Id == _.Id, v => v.TicketTypeInCollections).FirstOrDefault();
             var collectionVM            = _mapper.Map <CollectionVM>(collection);
             collectionVM.TicketTypes    = new List <TicketTypeDetailVM1>();
             var ticketTypeInCollections = collection.TicketTypeInCollections;
             ticketTypeInCollections.ToList().ForEach(t =>
             {
                 //var ticketType = _iTicketTypeService.GetTicketTypeById(t.TicketTypeId);
                 var ticketType  = _iTicketTypeService.GetAllTicketType(_ => _.Id == t.TicketTypeId, _ => _.Atrraction).FirstOrDefault();
                 var tickeTypeVM = _mapper.Map <TicketTypeDetailVM1>(ticketType);
                 collectionVM.TicketTypes.Add(tickeTypeVM);
             });
             result.Collections.Add(collectionVM);
         });
         var userPasses = _iUserPassService.GetAllUserPass(_ => _.PassId == id && _.Rate != 0);
         var totalRate  = userPasses.Count();
         var rateSum    = userPasses.Sum(_ => _.Rate);
         result.Rate      = totalRate != 0 ? (double)rateSum / (double)totalRate : 5;
         result.Feedbacks = userPasses.Select(_ => _.Feedback).ToList();
         return(Ok(result));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }