public DiscountViewModel(IUnitOfWork _unitOfWork, ConnectionPath _connectionpath, SearchViewModel _searchViewModel, IEventAggregator _eventAggregator, User _currentUser)
 {
     unitOfWork      = _unitOfWork;
     connectionpath  = _connectionpath;
     searchViewModel = _searchViewModel;
     eventAggregator = _eventAggregator;
     currentUser     = _currentUser;
     try
     {
         Discounts.AddRange(unitOfWork.GetDiscounts);
     }
     catch (AggregateException e)
     {
         SendMessage(InformationToUser.ServerError);
         Cancel();
         return;
     }
 }
Пример #2
0
 public BuyTicketViewModel(IUnitOfWork _unitOfWork, ConnectionPath _connectionpath, DiscountViewModel _discountViewModel, IEventAggregator _eventAggregator, User _currentUser, Ticket _ticket, bool randomSeats)
 {
     unitOfWork        = _unitOfWork;
     connectionpath    = _connectionpath;
     discountViewModel = _discountViewModel;
     eventAggregator   = _eventAggregator;
     Way         = connectionpath.Way;
     currentUser = _currentUser;
     Ticket      = _ticket;
     if (randomSeats)
     {
         RandomNext();
     }
     else
     {
         CalculateReservationTask();
     }
 }
        public override bool OnMouseButtonDown(MouseButtonEditorEventArgs args)
        {
            if (previewConnectionPath != null)
            {
                // It's the confirm click, skip this event
                return(true);
            }

            mDragLastPoint = args.Position;

            previewConnectionPath = new ConnectionPath();
            //previewContainer.ContentTemplate = ConnectionTemplate;
            previewConnectionPath.DataContext = new Connection(node, nodeOutput, null, null);
            previewConnectionPath.Brush       = Brushes.SkyBlue;

            nodeEditor.AddPreviewElement(previewConnectionPath);

            mMouseDownTime = DateTime.Now;

            return(true);
        }
Пример #4
0
        public List <int> GetSeats(ConnectionPath conpath, int from, int to)
        {
            List <int> freeseats = new List <int>();

            List <ConnectionPart> conparts = new List <ConnectionPart>();

            conparts.AddRange(conpath.ConnectionsParts.GetRange(from, to - from + 1));
            List <int[]> allseats = new List <int[]>();

            foreach (var part in conparts)
            {
                string seats = Services.GetConnectionPart(client, part).Seats;
                if (seats == "")
                {
                    return(freeseats);
                }
                allseats.Add(seats.Split(';').Select(Int32.Parse).ToArray());
            }

            int[] table = new int[120];
            foreach (var list in allseats)
            {
                foreach (var s in list)
                {
                    table[s]++;
                }
            }

            int count = to - from + 1;

            for (int i = 0; i < table.Count(); i++)
            {
                if (table[i] == count)
                {
                    freeseats.Add(i);
                }
            }
            return(freeseats);
        }
        public BuyTicketSummaryPriceViewModel(IEasyTrainTicketsDbEntities dbContext, string conIds, string qualityDiscount)
        {
            List <int> qualDiscount = JsonConvert.DeserializeObject <int[]>(qualityDiscount).ToList();

            Dict = new Dictionary <Discount, int>();
            List <Discount> discounts = dbContext.Discounts.ToList();

            for (int i = 0; i < discounts.Count; i++)
            {
                Dict.Add(discounts[i], qualDiscount[i]);
            }
            List <int> list = new List <int>();

            foreach (var key in Dict.Keys)
            {
                list.Add(Dict[key]);
            }
            ListDiscount = JsonConvert.SerializeObject(list);

            ConIds = conIds;
            List <ConnectionPart> conParts = JsonConvert.DeserializeObject <List <ConnectionPart> >(conIds);
            ConnectionPath        conPath  = new ConnectionPath()
            {
                ConnectionsParts = conParts
            };

            conPath.Initialize();
            decimal count = 0;

            foreach (var key in Dict.Keys)
            {
                count += (decimal)(Dict[key] * key.Percent);
            }
            Price = Math.Round(count * conPath.Price, 2);
            conPath.WriteConnection();
            Way = conPath.Way;
        }
Пример #6
0
 public void setConnectionPath(ConnectionPath connectionPath)
 {
     this.connectionPath = connectionPath;
 }
Пример #7
0
    private void computeConnection()
    {
        if (this.startNode.testCompatibility(this.endNode) == false)
        {
            this.connectionLength = -1;
        }
        else
        {
            if (this.startNode.getNodeLocation() == this.endNode.getNodeLocation())
            {
                this.connectionLength = this.startNode.getNodeLocation().getLocationLength();
                List <Location> toAdd = new List <Location>();
                toAdd.Add(this.startNode.getNodeLocation());
                this.connectionPath = new ConnectionPath(toAdd, this.connectionLength);
            }
            else
            {
                ConnectionPath discoveredPath                     = new ConnectionPath();
                PriortyQueue <ConnectionPath> pathQueue           = new PriortyQueue <ConnectionPath>();
                Dictionary <Location, int>    discoveredLocations = new Dictionary <Location, int>();

                discoveredPath.addLocation(startNode.getNodeLocation());
                discoveredLocations.Add(startNode.getNodeLocation(), 1);

                pathQueue.Enqueue(discoveredPath);
                bool found = false;

                int count = 0;
                while (found == false && pathQueue.IsEmpty() == false)
                {
                    ConnectionPath current_path = new ConnectionPath(pathQueue.GetFirst());
                    pathQueue.Dequeue();
                    Location currentLocation = current_path.GetMostRecentLocation();

                    for (int i = 0; i < currentLocation.getAdjacentLocations().Count; i++)
                    {
                        ConnectionPath new_path         = new ConnectionPath(current_path);
                        Location       neighborLocation = currentLocation.getAdjacentLocations()[i];


                        if (neighborLocation.getLocationLength() == -1)
                        {
                            continue;
                        }
                        if (neighborLocation.getLocationName() == this.endNode.getNodeLocation().getLocationName())
                        {
                            new_path.addLocation(neighborLocation);
                            discoveredPath = new_path;
                            found          = true;
                            break;
                        }
                        else if (discoveredLocations.ContainsKey(neighborLocation) == false)
                        {
                            new_path.addLocation(neighborLocation);
                            pathQueue.Enqueue(new_path);
                            discoveredLocations.Add(neighborLocation, 1);
                            count++;
                        }
                    }
                }
                this.connectionPath   = discoveredPath;
                this.connectionLength = discoveredPath.getPathWeight();
            }
        }
    }
Пример #8
0
 public ActionResult BuyTicket(ConnectionPath connectionPath)
 {
     return(RedirectToAction("Index", "BuyTicket", connectionPath));
 }