internal static void Compare(ITicket ticket, TicketDTO dto)
        {
            Assert.IsTrue(ticket != null);
            Assert.IsTrue(dto != null);

            Assert.AreEqual(ticket.TicketId, dto.Ticket.TicketId);
            Assert.AreEqual(MtsTicketHelper.Convert(ticket.Timestamp), dto.Ticket.TimestampUtc);
            Assert.AreEqual(ticket.Version, dto.Ticket.Version);

            Assert.AreEqual(ticket.AltStakeRefId, dto.Ticket.AltStakeRefId);
            Assert.AreEqual(ticket.OddsChange.ToString(), dto.Ticket.OddsChange.ToString());
            Assert.AreEqual(ticket.ReofferId, dto.Ticket.ReofferRefId);
            Assert.AreEqual(ticket.TestSource, dto.Ticket.TestSource);

            Assert.AreEqual(ticket.Sender.BookmakerId, dto.Ticket.Sender.BookmakerId);
            Assert.AreEqual(MtsTicketHelper.Convert(ticket.Sender.Channel), dto.Ticket.Sender.Channel);
            Assert.AreEqual(ticket.Sender.Currency.ToUpper(), dto.Ticket.Sender.Currency.ToUpper());
            Assert.AreEqual(ticket.Sender.LimitId, dto.Ticket.Sender.LimitId);
            Assert.AreEqual(ticket.Sender.ShopId, dto.Ticket.Sender.ShopId);
            Assert.AreEqual(ticket.Sender.TerminalId, dto.Ticket.Sender.TerminalId);
            Assert.AreEqual(ticket.Sender.EndCustomer.Id, dto.Ticket.Sender.EndCustomer.Id);
            Assert.AreEqual(ticket.Sender.EndCustomer.Confidence, dto.Ticket.Sender.EndCustomer.Confidence);
            Assert.AreEqual(ticket.Sender.EndCustomer.DeviceId, dto.Ticket.Sender.EndCustomer.DeviceId);
            Assert.AreEqual(ticket.Sender.EndCustomer.Ip, dto.Ticket.Sender.EndCustomer.Ip);
            Assert.AreEqual(ticket.Sender.EndCustomer.LanguageId, dto.Ticket.Sender.EndCustomer.LanguageId);

            for (var i = 0; i < ticket.Bets.Count(); i++)
            {
                Compare(ticket.Bets.ToList()[i], dto.Ticket.Bets.ToList()[i]);
            }

            for (var i = 0; i < ticket.Selections.Count(); i++)
            {
                var ticketSelection = ticket.Selections.ToList()[i];
                var dtoSelection    = dto.Ticket.Selections.First(f => f.Id == ticketSelection.Id && f.EventId == ticketSelection.EventId && f.Odds == ticketSelection.Odds);
                Compare(ticketSelection, dtoSelection);
            }
            Assert.IsFalse(string.IsNullOrEmpty(ticket.CorrelationId));
            Assert.AreEqual(ticket.TotalCombinations, dto.Ticket.TotalCombinations);
        }
Пример #2
0
        public async Task <IHttpActionResult> PostTicket(Ticket ticket)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            EventWithTicket query =
                (from data in db.EventsWithTickets
                 where (data.EventWithTicketID == ticket.EventWithTicketID)
                 select data).SingleOrDefault();

            if (query.MaxTicket > 0)
            {
                try
                {
                    db.Tickets.Add(ticket);
                    query.MaxTicket--;
                    await db.SaveChangesAsync();

                    db.Entry(ticket).Reference(x => x.Person).Load();
                    var dto = new TicketDTO()
                    {
                        TicketID          = ticket.TicketID,
                        Price             = ticket.Price,
                        EventWithTicketID = ticket.EventWithTicketID,
                        PersonID          = ticket.DNI
                    };

                    return(CreatedAtRoute("DefaultApi", new { id = ticket.TicketID }, ticket));
                }
                catch {}
            }
            else if (query.MaxTicket == 0)
            {
                query.HasTickets = false; db.SaveChanges();
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        [Test] //behavior test
        public void Update_When_entity_is_invalid_Then_it_makes_no_calls_to_repository_and_unit_of_work()
        {
            // Arrange
            var ticketDTOToUpdate = new TicketDTO()
            {
                Id       = 3,
                Price    = 10.23,
                FlightId = 3
            };

            var ticketRepositoryFake = A.Fake <ITicketRepository>();
            var unitOfWorkFake       = A.Fake <IUnitOfWork>();
            var ticketService        = new TicketService(unitOfWorkFake, AlwaysInValidValidator);

            // Act + Assert
            var exception = Assert.Throws <BadRequestException>(() => ticketService.Update(ticketDTOToUpdate));

            A.CallTo(() => ticketRepositoryFake.Update(A <Ticket> ._)).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.TicketRepository).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.Set <Ticket>()).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.SaveChanges()).MustNotHaveHappened();
        }
Пример #4
0
        public List <TicketDTO> getTicketsByShowID(int ID)
        {
            List <TicketDTO> ticketByShow = new List <TicketDTO>();
            SqlCommand       cmd          = connectToDB();

            cmd.Parameters.AddWithValue("ShowID", ID);
            cmd.CommandText = "select * from Tickets where ShowID = @ShowID";
            SqlDataReader dataReader = cmd.ExecuteReader();

            while (dataReader.Read())
            {
                TicketDTO ticket = new TicketDTO();
                ticket.setID((Int32)dataReader["ID"]);
                ticket.setShowID((Int32)dataReader["ShowID"]);
                ticket.setRow((Int32)dataReader["Row"]);
                ticket.setColumn((Int32)dataReader["Col"]);
                ticketByShow.Add(ticket);
            }
            cmd.Connection.Close();

            return(ticketByShow);
        }
Пример #5
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"));
        }
Пример #6
0
        public async Task <TicketDTO> ProcurarPorID(int id)
        {
            var ticket = context.Tickets.FirstOrDefault(t => t.Id == id);

            if (ticket == null)
            {
                return(null);
            }

            TicketDTO ticketDTO = new TicketDTO()
            {
                Id           = ticket.Id,
                Titulo       = ticket.Titulo,
                Descricao    = ticket.Descricao,
                DataAbertura = Convert.ToString(ticket.DataAbertura),
                Categoria    = ticket.Categoria.Nome,
                Prioridade   = ticket.PrioridadeAtual.ToString(),
                Criador      = ticket.Criador.Nome
            };

            return(await Task.FromResult(ticketDTO));
        }
        public IHttpActionResult GetTickets()
        {
            List <Ticket>    Tickets    = db.Tickets.ToList();
            List <TicketDTO> TicketDTOs = new List <TicketDTO> {
            };

            foreach (var specificTicket in Tickets)
            {
                TicketDTO NewTicket = new TicketDTO
                {
                    TicketId    = specificTicket.TicketId,
                    TicketTitle = specificTicket.TicketTitle,
                    TicketBody  = specificTicket.TicketBody,
                    TicketDate  = specificTicket.TicketDate,
                    UserID      = specificTicket.UserID,
                    User        = specificTicket.User
                };
                TicketDTOs.Add(NewTicket);
            }

            return(Ok(TicketDTOs));
        }
Пример #8
0
        public async Task <ActionResult <TicketDTO> > PostAsync(int projectId, TicketDTO ticket)
        {
            if (ticket is null)
            {
                return(BadRequest());
            }
            if (!await _repo.ProjectExistsAsync(projectId))
            {
                return(NotFound("Project not found"));
            }
            if (ticket.Submitter is null || !await _repo.UserExistsAsync(ticket.Submitter.UserId))
            {
                return(NotFound("Submitter not found"));
            }
            if (ticket.Dev != null && ticket.Dev.UserId != 0 && !await _repo.UserExistsAsync(ticket.Dev.UserId))
            {
                return(NotFound("Dev not found"));
            }
            if (ticket.Priority is null || !await _repo.PriorityExistsAsync(ticket.Priority))
            {
                return(NotFound("Priority not found"));
            }
            if (ticket.Status is null || !await _repo.StatusExistsAsync(ticket.Status))
            {
                return(NotFound("Status not found"));
            }
            if (ticket.Type is null || !await _repo.TypeExistsAsync(ticket.Type))
            {
                return(NotFound("Type not found"));
            }

            var newId = await _repo.CreateTicketAsync(projectId, ticket);

            return(CreatedAtAction(
                       nameof(GetAsync),
                       new { ticketId = newId },
                       await _repo.ReadTicketAsync(newId)
                       ));
        }
Пример #9
0
        public async Task <ActionResult> PutAsync(TicketDTO ticket)
        {
            if (ticket is null)
            {
                return(BadRequest("Ticket is null"));
            }
            if (!await _repo.TicketExistsAsync(ticket.TicketId))
            {
                return(NotFound("Ticket not found"));
            }
            if (ticket.Submitter is null || !await _repo.UserExistsAsync(ticket.Submitter.UserId))
            {
                return(NotFound("Submitter not found"));
            }
            if (ticket.Dev != null && ticket.Dev.UserId != 0 && !await _repo.UserExistsAsync(ticket.Dev.UserId))
            {
                return(NotFound("Dev not found"));
            }
            if (ticket.Updater is null || !await _repo.UserExistsAsync(ticket.Updater.UserId))
            {
                return(NotFound("Submitter not found"));
            }
            if (ticket.Priority is null || !await _repo.PriorityExistsAsync(ticket.Priority))
            {
                return(NotFound("Priority not found"));
            }
            if (ticket.Status is null || !await _repo.StatusExistsAsync(ticket.Status))
            {
                return(NotFound("Status not found"));
            }
            if (ticket.Type is null || !await _repo.TypeExistsAsync(ticket.Type))
            {
                return(NotFound("Type not found"));
            }

            await _repo.UpdateTicketAsync(ticket);

            return(NoContent());
        }
Пример #10
0
 public void UpdateTicket(TicketDTO value)
 {
     if (value != null)
     {
         Ticket changedTicket = mapper.Map <TicketDTO, Ticket>(value);
         var    tickets       = unitOfWork.FlightRepository.GetById(value.FlightId).Tickets;
         var    ticket        = tickets.Find(k => k.Id == value.Id);
         if (ticket != null)
         {
             tickets.Remove(ticket);
             tickets.Add(changedTicket);
         }
         else
         {
             throw new Exception("Error: There is no such ticket in this flight.");
         }
     }
     else
     {
         throw new ArgumentNullException();
     }
 }
Пример #11
0
        public WebAPITests()
        {
            server = new TestServer(new WebHostBuilder()
                                    .UseEnvironment("Testing")
                                    .UseStartup <Startup>());
            client = server.CreateClient();

            F1 = new FlightDTO
            {
                Number        = "PS101",
                Departure     = "London",
                DepartureTime = DateTime.Now + new TimeSpan(0, 30, 45),
                Destination   = "Paris",
                ArrivalTime   = DateTime.Now + new TimeSpan(3, 15, 0),
            };
            ticketOut = new TicketDTO {
                Id = 1, FlightNumber = "PS101", Price = 400, FlightId = F1.Id
            };
            ticketIn = new Ticket {
                Id = 1, FlightNumber = "PS101", Price = 400, FlightId = F1.Id
            };
        }
Пример #12
0
        public void RefreshTickets()
        {
            int    price     = trainService.Get(SelectedTrainId).Data.RoutePropereties.Last().Price;
            VanDTO neededVan = vanService.Get(SelectedVanId).Data;

            int idClass = neededVan.ClassProperetiesId;

            price += classProperetiesService.Get(idClass).Data.Price;

            int passangerId = passangerService.GetAll()
                              .Data.Last().Id;


            TicketDTO ticket = new TicketDTO()
            {
                VanId       = SelectedVanId,
                SeatId      = SelectedSeatId,
                TrainId     = SelectedTrainId,
                Price       = price,
                PassangerId = passangerId
            };

            SelectedStation = stationService.Get(SelectedStationId).Data;
            SelectedTrain   = trainService.Get(SelectedTrainId).Data;
            SelectedVan     = vanService.Get(SelectedVanId).Data;
            SelectedSeat    = seatService.Get(SelectedSeatId).Data;

            ticketService.Add(ticket);

            ticketService.Save();

            Ticket = ticket;
            OnPropertyChanged(nameof(SelectedStation));
            OnPropertyChanged(nameof(SelectedTrain));
            OnPropertyChanged(nameof(SelectedVan));
            OnPropertyChanged(nameof(SelectedSeat));
            OnPropertyChanged(nameof(Ticket));
            OnPropertyChanged(nameof(Stations));
        }
Пример #13
0
        public void CreateTest()
        {
            //Arrange
            var ticket = new Ticket()
            {
                Price = 400, FlightId = 1
            };
            var ticketDTO = new TicketDTO()
            {
                Price = 400, FlightID = 1
            };

            List <Ticket> tickets = new List <Ticket>();

            ticketMockRepository.Setup(x => x.GetAll()).Returns(tickets);
            ticketMockRepository.Setup(x => x.Create(ticket)).Callback((Ticket t) => { tickets.Add(new Ticket()); });
            mapper.Setup(x => x.Map <Ticket>(ticketDTO)).Returns(ticket);

            ticketService.Create(ticketDTO);

            Assert.Single(ticketService.GetAll());
        }
Пример #14
0
        public async void SendConfirmationNotification(string emailAddress, TicketDTO ticket)
        {
            await Task.Run(async() =>
            {
                var client = new SendGridClient(apiKey);
                var msg    = new SendGridMessage();

                msg.SetFrom(new EmailAddress("*****@*****.**", "Grievance Team"));
                var recipients = new List <EmailAddress>
                {
                    new EmailAddress(emailAddress, ticket.CreatedBy)
                };

                msg.AddTos(recipients);
                msg.SetSubject(string.Format("Grievance System - Reference Number: {0}", ticket.ReferenceNumber));

                var emailBody = Resources.ConfirmationEmail.ToString().Replace("@Name", ticket.Name).Replace("@TicketDescription", ticket.Description).Replace("@TimeLogged", ticket.CreatedDate.ToString("f")).Replace("@Complainant", ticket.CreatedBy);

                msg.AddContent(MimeType.Html, emailBody);

                var response = await client.SendEmailAsync(msg);
            });
        }
Пример #15
0
        public async Task <TicketDTO> CreateTicket(int flightId, TicketDTO value)
        {
            var flight = await unit.FlightsRepo.GetEntityById(flightId);

            if (flight != null)
            {
                var ticket = mapper.Map <TicketDTO, Ticket>(value) ?? throw new AutoMapperMappingException("Error: Can't map the TicketDTO into Ticket");
                if (flight.Tickets.Contains(ticket))
                {
                    throw new Exception("Error: Can't add this ticket to the the flight!");
                }
                flight.Tickets.Add(ticket);
                var result = await unit.FlightsRepo.Update(flight);

                await unit.SaveChangesAsync();

                return(mapper.Map <Ticket, TicketDTO>(ticket) ?? throw new AutoMapperMappingException("Error: Can't map the Ticket into TicketDTO"));
            }
            else
            {
                throw new Exception("Error: Can't find such flight!");
            }
        }
        public async Task UpdateEntityAsync(int id, TicketDTO ticketDTO)
        {
            var ticket = await ticketRepository.GetAsync(id);

            if (ticket == null)
            {
                throw new ValidationException($"Ticket with this id {id} not found");
            }
            if (ticketDTO.Price > 0)
            {
                ticket.Price = ticketDTO.Price;
            }
            if (ticketDTO.FlightNumber > 0)
            {
                ticket.FlightNumber = ticketDTO.FlightNumber;
            }
            if (ticketDTO.FlightId > 0)
            {
                ticket.FlightId = ticketDTO.FlightId;
            }

            await ticketRepository.UpdateAsync(ticket).ConfigureAwait(false);
        }
Пример #17
0
        public async Task <int> CreateTicketAsync(int projectId, TicketDTO ticketDTO)
        {
            var ticket = new Ticket()
            {
                Title       = ticketDTO.Title,
                Description = ticketDTO.Description,
                Project     = await _db.Project.SingleAsync(x => x.ProjectId == projectId),
                Submitter   = await _db.Users.SingleAsync(x => x.UserId == ticketDTO.Submitter.UserId),
                Priority    = await _db.TicketPriority.SingleAsync(x => x.Name == ticketDTO.Priority),
                Status      = await _db.TicketStatus.SingleAsync(x => x.Name == ticketDTO.Status),
                Type        = await _db.TicketType.SingleAsync(x => x.Name == ticketDTO.Type)
            };

            if (ticketDTO.Dev != null)
            {
                ticket.Dev = await _db.Users.SingleOrDefaultAsync(x => x.UserId == ticketDTO.Dev.UserId);
            }

            _db.Ticket.Add(ticket);
            await _db.SaveChangesAsync();

            return(ticket.TicketId);
        }
Пример #18
0
        public async Task UpdateTicketAsync(TicketDTO ticketDTO)
        {
            var ticket = await _db.Ticket.SingleAsync(x => x.TicketId == ticketDTO.TicketId);

            ticket.Title       = ticketDTO.Title;
            ticket.Description = ticketDTO.Description;
            ticket.Submitter   = await _db.Users.SingleAsync(x => x.UserId == ticketDTO.Submitter.UserId);

            ticket.Updater = await _db.Users.SingleAsync(x => x.UserId == ticketDTO.Updater.UserId);

            ticket.Priority = await _db.TicketPriority.SingleAsync(x => x.Name == ticketDTO.Priority);

            ticket.Status = await _db.TicketStatus.SingleAsync(x => x.Name == ticketDTO.Status);

            ticket.Type = await _db.TicketType.SingleAsync(x => x.Name == ticketDTO.Type);

            if (ticketDTO.Dev != null)
            {
                ticket.Dev = await _db.Users.SingleOrDefaultAsync(x => x.UserId == ticketDTO.Dev.UserId);
            }

            await _db.SaveChangesAsync();
        }
Пример #19
0
        public void AddTicket(TicketDTO newTicketDTO)
        {
            using (var ctx = new SkyScannerContext())
            {
                //todo altceva
                //if (newTicketDTO.AddressId == 0)
                //{
                //    var newAddressDTO = newTicketDTO.Address;
                //    var newAddress = Mapper.Map<AddressDTO, Address>(newAddressDTO);
                //    var addedAddress = ctx.Addresses.Add(newAddress);
                //    newTicketDTO.AddressId = addedAddress.AddressId;
                //}

                //Verific daca datele introduse sunt deja salvate in tabela de adrese
                var addressId = 0;
                //var addressId = ctx.Addresses.AsNoTracking().FirstOrDefault(x => x.Country == newTicketDTO.Address.Country && x.City == newTicketDTO.Address.City &&
                //        x.Street == newTicketDTO.Address.Street && x.Number == newTicketDTO.Address.Number).AddressId;
                if (addressId == 0)
                {
                    //Daca nu sunt deja in baza de date adaug o noua adresa
                    addressId = _addressService.AddAddress(newTicketDTO.Address);
                }

                newTicketDTO.AddressId = addressId;
                var newTicket = Mapper.Map <TicketDTO, Ticket>(newTicketDTO);

                //Daca un utilizator cumpara un bilet vam face ca locul respectiv sa nu mai fie isponibil
                var seat = ctx.SeatLists.Where(x => x.SeatId == newTicket.SeatId).FirstOrDefault();
                seat.Available = false;

                //Adaugam biletul
                ctx.Tickets.Add(newTicket);

                //Salvam toate modificarile
                ctx.SaveChanges();
            }
        }
Пример #20
0
        public TicketDTO Create(TicketDTO newTicketDTO)
        {
            if (string.IsNullOrWhiteSpace(newTicketDTO.Name))
            {
                throw new ValidationException("Ticket name is empty");
            }

            var newTicket = _mapper.Map <Ticket>(newTicketDTO);

            //var previousTicket = _database.Tickets.Find(t => t.ColumnId == newTicket.ColumnId && t.NextTicketId == null).SingleOrDefault();

            //newTicket.PreviousTicketId = previousTicket?.Id;

            //newTicket.NextTicketId = null;

            _database.Tickets.Create(newTicket);

            //if (previousTicket != null)
            //    previousTicket.NextTicketId = newTicket.Id;

            _database.Save();

            return(_mapper.Map <TicketDTO>(newTicket));
        }
Пример #21
0
        public async Task <bool> CreateTicketAsync(TicketDTO ticket)
        {
            Session activeSession = await Task.Run(() => ActiveSessionAsync());

            User isItValidUser = await Task.Run(() => _userRepository.GetAll().FirstOrDefault(u => u.UserId == ticket.UserId));

            if (activeSession != null && isItValidUser != null)
            {
                bool check = await CheckForDuplicateNumbersAsync(ticket);

                if (check)
                {
                    ticket.SessionId = activeSession.SessionId;
                    int result = await Task.Run(() => _ticketRepository.Add(_mapper.Map <Ticket>(ticket)));

                    if (result != -1)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public async Task <TicketDTO> BuyTicket(TicketDTO ticketDTO)
        {
            Tour tour = DataBase.TourManager.Get(ticketDTO.TourId);

            if (tour == null)
            {
                throw new ValidationException("There is no information about this tour", tour.Name);
            }
            if (ticketDTO == null)
            {
                throw new ValidationException("There is no information", $"{ticketDTO.Id}");
            }
            ApplicationUser user = await DataBase.UserManager.FindByIdAsync(ticketDTO.UserId);

            if (user == null)
            {
                throw new ValidationException("There is no information about this user", user.UserName);
            }
            if (tour.PlacesCount < 1)
            {
                throw new ValidationException("There is no free places", tour.Name);
            }
            Ticket ticket = new Ticket
            {
                UserId       = ticketDTO.UserId,
                TourId       = ticketDTO.TourId,
                PurchaseDate = DateTime.Now,
                IsSold       = true
            };

            DataBase.TicketManager.Create(ticket);
            tour.PlacesCount--;
            await DataBase.SaveAsync();

            return(Mapper.Map <TicketDTO>(ticket));
        }
Пример #23
0
        [Test] // behaviour
        public void Update_When_entity_is_updated_Then_it_makes_calls_to_repository_and_unit_of_work()
        {
            // Arrange
            var ticketDTOToUpdate = new TicketDTO()
            {
                Id       = 3,
                Price    = 10.23,
                FlightId = 3
            };

            var ticketRepositoryFake = A.Fake <ITicketRepository>();
            var unitOfWorkFake       = A.Fake <IUnitOfWork>();

            A.CallTo(() => unitOfWorkFake.Set <Ticket>()).Returns(ticketRepositoryFake);
            var ticketService = new TicketService(unitOfWorkFake, AlwaysValidValidator);

            // Act
            var result = ticketService.Update(ticketDTOToUpdate);

            // Assert
            A.CallTo(() => ticketRepositoryFake.Update(A <Ticket> ._)).MustHaveHappenedOnceExactly();
            A.CallTo(() => unitOfWorkFake.Set <Ticket>()).MustHaveHappenedOnceExactly();
            A.CallTo(() => unitOfWorkFake.SaveChanges()).MustHaveHappenedOnceExactly();
        }
        public void Get_Should_get_flight_by_id()
        {
            // Arrange

            var ticketservice = A.Fake <ITicketsService>();

            A.CallTo(() => ticketservice.GetById(A <int> ._)).Returns(ticket1In);

            var ticketsController = new TicketsController(ticketservice);

            //Act
            var actionResult = ticketsController.Get(1);

            //Assert
            Assert.NotNull(actionResult);

            OkObjectResult result = actionResult as OkObjectResult;

            Assert.NotNull(result);

            TicketDTO ticketDTOResult = result.Value as TicketDTO;

            Assert.AreEqual(ticket1In, ticketDTOResult);
        }
        public void UpdateEntity(int id, TicketDTO ticketDTO)
        {
            var ticket = ticketRepository.Get(id);

            if (ticket == null)
            {
                throw new ValidationException($"Ticket with this id {ticketDTO.Id} not found");
            }
            if (ticketDTO.Price > 0)
            {
                ticket.Price = ticketDTO.Price;
            }
            if (ticketDTO.FlightNumber > 0)
            {
                ticket.FlightNumber = ticketDTO.FlightNumber;
            }
            if (ticketDTO.FlightId > 0)
            {
                ticket.FlightId = ticketDTO.FlightId;
            }


            ticketRepository.Update(ticket);
        }
Пример #26
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            var turple    = RenderCreate();
            var btnCreate = turple.Item1;
            var number    = turple.Item2;
            var price     = turple.Item3;

            btnCreate.Click += async(object sen, RoutedEventArgs evArgs) =>
            {
                var ticketCreating = new TicketDTO()
                {
                    FlightNumber = number.Text, Price = double.Parse(price.Text)
                };
                try
                {
                    await service.CreateAsync(ticketCreating);
                }
                catch (Exception) { }

                ticketList.Add(ticketCreating);
                UpdateList();
                SingleItem.Children.Clear();
            };
        }
Пример #27
0
        public ActionResult MakePurchase(PlaceViewModel tk)
        {
            try {
                var tr     = rs.AllRoutes().FirstOrDefault(t => t.Number == tk.Train).Stops;
                var ticket = new TicketDTO
                {
                    PassName       = AuthManager.User.Identity.Name,
                    Type           = tk.Type,
                    DepStation     = tk.DepStation,
                    ArrivalStation = tk.ArrivalStation,
                    Departure      = tr.FirstOrDefault(s => s.StopStation == tk.DepStation).Departure,
                    Arrival        = tr.FirstOrDefault(s => s.StopStation == tk.ArrivalStation).Arrival,
                };

                var res = ts.AddTickets(ticket, tk.Train);
                unit.Save();
                unit.Dispose();
                return(RedirectToAction("HomePage", "Home"));
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
        }
Пример #28
0
        public async Task ValidationMappingTicket_when_validate_pilot_OK_then_map()
        {
            var       validator = new TicketDTOValidator();
            TicketDTO correct   = new TicketDTO()
            {
                Id           = 1,
                FlightNumber = 5
            };

            TicketDTO incorrect = new TicketDTO()
            {
                Id           = 2,
                FlightNumber = 0,
                Price        = 55
            };

            bool correctRes = validator.Validate(correct).IsValid;

            Assert.True(correctRes);
            var mapped = _mapper.Map <TicketDTO, Ticket>(correct);

            if (correctRes)
            {
                await _service.Post(mapped);
            }

            bool incorrectRes = validator.Validate(incorrect).IsValid;

            Assert.False(incorrectRes);
            var mappedIncorrect = _mapper.Map <TicketDTO, Ticket>(incorrect);

            if (incorrectRes)
            {
                await _service.Post(mapped);
            }
        }
Пример #29
0
        private async Task <TicketDTO> MapTicketToDto(SupportTicket ticket)
        {
            var result = new TicketDTO
            {
                Id = ticket.Id,
                AssignedToStaffId = ticket.AssignedTo == null ? 0 : ticket.AssignedTo.Value,
                DateEnabled       = ticket.DtCreated.Value,
                Description       = ticket.Message,
                Price             = 0
            };
            var client = await clientSvc.GetClientById(ticket.UserId);

            result.ClientName = client != null ? client.Firstname + " " + client.Surname : "";

            if (ticket.AssignedTo != null)
            {
                var staff = await staffService.GetStaffById(ticket.AssignedTo.Value);

                result.AssignedToStaffName = staff?.Firstname + " " + staff?.Surname;
            }


            return(result);
        }
Пример #30
0
        public int CreateTicket(TicketDTO dto)
        {
            var sqlModel = Mapper.Map(dto);

            return(CRUDRepositoryHelper.Create(sqlModel));
        }