public void TestBuy() { var x = 6; var y = 5; var quant = 6; var multi = 3.5; api.AddBox(new Box() { X = x, Y = y, Quantity = quant }); var search = new SearchTicket(); search.X = x; search.Y = y; search.MaxDifBoxes = 10; search.MaxSizeMulti = multi; search.Amount = quant; bool res; var orders = api.Search(search, out res); Assert.IsTrue(res); var toBuy = orders.Sum(a => a.Amount); var beforeBuy = api.CountBoxes; api.BuyBoxes(orders); var AfterBuy = api.CountBoxes; Assert.IsTrue(beforeBuy - AfterBuy == toBuy); }
public void TestSearch() { var x = 4; var y = 6; var quant = 3; var multi = 3.5; api.AddBox(new Box() { X = x, Y = y }); var search = new SearchTicket(); search.X = x; search.Y = y; search.MaxDifBoxes = 10; search.MaxSizeMulti = multi; search.Amount = quant; bool res; var orders = api.Search(search, out res); Assert.IsTrue(res); Assert.IsTrue(orders.Sum(a => a.Amount) > 1); }
public async Task <ActionResult> Lookup(SearchTicket search) { search.searchStr = search.searchStr == null ? "EMPTY SEARCH" : search.searchStr; if (search.searchStr == "EMPTY SEARCH") { return(RedirectToAction("Index", new { id = 1 })); } var existsEvent = false; var client = new ViagogoClient("TaRJnBcw1ZvYOXENCtj5", "ixGDUqRA5coOHf3FQysjd704BPptwbk6zZreELW2aCYSmIT8XJ9ngvN1MuKV", new ProductHeaderValue("AwesomeApp", "1.0")); var token = await client.OAuth2.GetClientAccessTokenAsync(/*List of scopes*/ new string[] { }); await client.TokenStore.SetTokenAsync(token); var searchResults = await client.Search.GetAllAsync(search.searchStr); List <Models.Event> eventcollection = new List <Models.Event>(); foreach (var res in searchResults) { if (res.Type == "Event") { var currEvent = await client.Hypermedia.GetAsync <GogoKit.Models.Response.Event>(res.EventLink); eventcollection.Add(new Models.Event() { eventName = res.Title, minticketprice = conv(currEvent.MinTicketPrice), eventDate = currEvent.StartDate, id = currEvent.Id }); existsEvent = true; } } Session["events"] = eventcollection; if (existsEvent) { FilterTicket filterobject = new FilterTicket(); filterobject.lst = eventcollection; return(View(filterobject)); } else { return(RedirectToAction("Index", new { id = 1 })); } }
public System.Collections.Generic.IEnumerable <BoxOrder> SearchBoxes(SearchTicket search, out bool succes) { var cart = dataManger.SearchBoxes(search.X, search.Y, search.Amount, search.MaxSizeMulti, search.MaxDifBoxes); var list = new LinkedList <BoxOrder>(); var boxesLeft = search.Amount; while (!cart.IsEmpty) { Box box; cart.Dequeue(out box); var toAdd = Math.Min(boxesLeft, box.Quantity); var order = new BoxOrder() { Box = box, Amount = toAdd }; boxesLeft -= toAdd; list.AddLast(order); } succes = boxesLeft == 0; return(list); }
public ActionResult <SearchTicket> Post([FromBody] CarSearch carSearch, [FromServices] IConfiguration config) { //assign searchresult var uniqueKey = Guid.NewGuid(); //start async search here Task.Run(() => { var results = new SearchHandler(_context).StartCarSearch(carSearch); string data = JsonConvert.SerializeObject(results.ScrapeResults, Formatting.None); var searchData = new SearchData { Key = uniqueKey, Data = data, Exception = results.RuntimeException?.Message, SearchDurationInSec = results.DurationInSeconds }; var util = new Util(config); using (var db = util.GetDbContext()) { db.SearchData.Add(searchData); db.SaveChanges(); } }); var returnTicket = new SearchTicket { SearchKey = uniqueKey.ToString(), RetryAfter = Duration.ThirtySeconds, KeyRetrievalEndpoint = string.Format("{0}://{1}{2}{3}", Request.Scheme, Request.Host, Request.Path, Request.QueryString)?.ToLower().Replace("startsearch", "getresults") }; return(new AcceptedResult("", returnTicket)); }
public IActionResult BuyTicket(SearchTicket searchTicket) { var viewmodel = new ViewModel(); viewmodel.LocationList = new Dictionary <int, Location>(); foreach (var item in _db.Location.ToList()) { viewmodel.LocationList.Add(item.Id, item); } viewmodel.RouteList = new Dictionary <int, Route>(); var routeList = _db.Route.Where(x => x.DepartureTime == searchTicket.DepartureTime && x.StartLocationId == searchTicket.LocationId).ToList(); foreach (var item in routeList) { viewmodel.RouteList.Add(item.Id, item); } ViewBag.viewModel = viewmodel; return(View(new ViewModel() { LocationList = viewmodel.LocationList, RouteList = viewmodel.RouteList })); }
public System.Collections.Generic.IEnumerable <BoxOrder> Search(SearchTicket search, out bool succes) => BoxStoreLogic.Instance.SearchBoxes(search, out succes);