コード例 #1
0
        // POST api/tickettypes
        public HttpResponseMessage CreateTicketType([FromBody] TicketTypeDTO TicketTypeDTO)
        {
            TicketType newTicketType = new TicketType();

            newTicketType.Price = TicketTypeDTO.Price;
            newTicketType.Name  = TicketTypeDTO.Name;
            foreach (var x in unitOfWork.PriceLists.GetAll())
            {
                foreach (var y in TicketTypeDTO.PriceLists)
                {
                    if (x.Id == y.Id)
                    {
                        newTicketType.PriceLists.Add(x);
                    }
                }
            }
            newTicketType.Tickets = TicketTypeDTO.Tickets;

            unitOfWork.TicketTypes.Add(newTicketType);
            unitOfWork.Complete();

            var message = Request.CreateResponse(HttpStatusCode.Created, newTicketType);

            message.Headers.Location = new Uri(Request.RequestUri + "/" + newTicketType.Id.ToString());

            return(message);
        }
コード例 #2
0
        // PUT api/tickettypes/5
        public HttpResponseMessage UpdateTicketType(int id, [FromBody] TicketTypeDTO TicketTypeDTO)
        {
            var TicketTypeToBeUpdated         = unitOfWork.TicketTypes.GetAll().Where(x => x.Id == id && x.Deleted == false).SingleOrDefault();
            List <PriceList> listOfPriceLists = new List <PriceList>();

            foreach (var x in unitOfWork.PriceLists.GetAll())
            {
                foreach (var y in TicketTypeDTO.PriceLists)
                {
                    if (x.Id == y.Id)
                    {
                        listOfPriceLists.Add(x);
                    }
                }
            }
            TicketTypeToBeUpdated.PriceLists.Clear();
            TicketTypeToBeUpdated.PriceLists = listOfPriceLists;
            TicketTypeToBeUpdated.Price      = TicketTypeDTO.Price;
            TicketTypeToBeUpdated.Name       = TicketTypeDTO.Name;

            if (TicketTypeToBeUpdated != null)
            {
                unitOfWork.TicketTypes.Update(TicketTypeToBeUpdated);
                unitOfWork.Complete();

                return(Request.CreateResponse(HttpStatusCode.OK, TicketTypeToBeUpdated));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "TicketType with that id number doesn't exist."));
            }
        }
コード例 #3
0
        public async Task <TicketTypeDTO> GetById(int id)
        {
            var ticketTypeDTO = new TicketTypeDTO();
            await Task.Run(() =>
            {
                var ticketType = _ctx.TicketCategories.FirstOrDefault(x => x.Id == id);
                if (ticketType == null)
                {
                    return;
                }
                var mappedTicketType = new TicketTypeDTO()
                {
                    CreatedBy   = ticketType.CreatedBy,
                    CreatedDate = ticketType.CreatedDate ?? default(DateTime),
                    Description = ticketType.Description,
                    Id          = ticketType.Id,
                    Name        = ticketType.Name,
                    UpdatedBy   = ticketType.UpdatedBy,
                    UpdatedDate = ticketType.UpdatedDate ?? default(DateTime)
                };
                ticketTypeDTO = mappedTicketType;
            });

            return(ticketTypeDTO);
        }
コード例 #4
0
        private IEnumerable <TicketDTO> GetTicketCollectionDTO()
        {
            var ticketType = new TicketTypeDTO()
            {
                TypeName = "econom"
            };

            return(new[]
            {
                new TicketDTO {
                    Id = 1, Price = 273, Type = ticketType
                },
                new TicketDTO {
                    Id = 2, Price = 112, Type = ticketType
                },
                new TicketDTO {
                    Id = 3, Price = 231, Type = ticketType
                },
                new TicketDTO {
                    Id = 4, Price = 221, Type = ticketType
                },
                new TicketDTO {
                    Id = 5, Price = 100, Type = ticketType
                },
                new TicketDTO {
                    Id = 6, Price = 321, Type = ticketType
                }
            });
        }
コード例 #5
0
 public TicketType Transform(TicketTypeDTO dto)
 {
     if (dto == null)
     {
         return(null);
     }
     return(new TicketType
     {
         TicketTypeId = dto.TicketTypeId,
         Name = dto.TicketTypeName,
         Description = dto.TicketTypeDescription
     });
 }
コード例 #6
0
 public TicketTypeDTO UpdateTicketType(TicketTypeDTO ticketType)
 {
     try
     {
         var tt = _ticketTypeFactory.Transform(ticketType);
         _uow.TicketTypes.Update(tt);
         _uow.SaveChanges();
         return(GetTicketTypeById(tt.TicketTypeId));
     }
     catch (DBConcurrencyException)
     {
         return(null);
     }
 }
コード例 #7
0
 public TicketTypeDTO AddNewTicketType(TicketTypeDTO newTicketType)
 {
     try
     {
         var tt = _ticketTypeFactory.Transform(newTicketType);
         _uow.TicketTypes.Add(tt);
         _uow.SaveChanges();
         return(_ticketTypeFactory.Transform(_uow.TicketTypes.Find(tt.TicketTypeId)));
     }
     catch (DBConcurrencyException)
     {
         return(null);
     }
 }
コード例 #8
0
        public async Task <TicketTypeDTO> Update(TicketTypeDTO type)
        {
            await Task.Run(() =>
            {
                var existingTicketType = _ctx.TicketTypes.FirstOrDefault(x => x.Id == type.Id);
                if (existingTicketType != null)
                {
                    existingTicketType.Description = type.Description;
                    existingTicketType.Name        = type.Name;
                    existingTicketType.UpdatedBy   = type.UpdatedBy;
                    existingTicketType.UpdatedDate = type.UpdatedDate;
                    _ctx.SaveChanges();
                }
            });

            return(type);
        }
コード例 #9
0
        public IHttpActionResult CreateTicket(TicketDTO ticketDTO, TicketTypeDTO ticketTypeDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var ticket      = Mapper.Map <TicketDTO, Ticket>(ticketDTO);
            var ticketTypes = Mapper.Map <TicketTypeDTO, TicketType>(ticketTypeDTO);

            _context.Tickets.Add(ticket);
            _context.SaveChanges();

            ticketDTO.Id = ticket.Id;

            return(Created(new Uri(Request.RequestUri + "/" + ticket.Id), ticketDTO));
        }
コード例 #10
0
        public async Task <TicketTypeDTO> Add(TicketTypeDTO type)
        {
            await Task.Run(() =>
            {
                var newTicketType = new Grievance.DAL.TicketType()
                {
                    CreatedBy   = type.CreatedBy,
                    CreatedDate = type.CreatedDate,
                    Description = type.Description,
                    Name        = type.Name,
                    UpdatedBy   = type.UpdatedBy,
                    UpdatedDate = type.UpdatedDate
                };
                _ctx.TicketTypes.Add(newTicketType);
                _ctx.SaveChanges();
            });

            return(type);
        }
コード例 #11
0
        public IActionResult AddTicket(AddTicketResultModel ticket)
        {
            var type    = _unitOfWork.TicketTypeRepository.Get(ticket.TypeID);
            var typeDTO = new TicketTypeDTO
            {
                Id       = type.Id,
                TypeName = type.TypeName
            };
            var ticketDTO = new TicketDTO()
            {
                Price    = ticket.Price,
                Type     = typeDTO,
                FlightID = ticket.FlightID
            };

            for (int i = 0; i < ticket.Amount; i++)
            {
                _ticketService.Create(ticketDTO);
            }

            return(RedirectToAction("GetAllTickets", "Admin"));
        }
コード例 #12
0
        public IActionResult AddTicket()
        {
            var flights     = _flightService.GetAll();
            var ticketTypes = _unitOfWork.TicketTypeRepository.GetAll();
            var typesDTO    = new List <TicketTypeDTO>();

            foreach (var t in ticketTypes)
            {
                var type = new TicketTypeDTO
                {
                    Id       = t.Id,
                    TypeName = t.TypeName
                };
                typesDTO.Add(type);
            }
            var addTicketModel = new AddTicketModel()
            {
                Flights = flights,
                Types   = typesDTO
            };

            return(View(addTicketModel));
        }
コード例 #13
0
        public async Task <TicketTypeDTO> Update(TicketTypeDTO type)
        {
            var newType = await _dataProvider.Update(type);

            return(newType);
        }