public async Task <IActionResult> Post( ListingRequest listingCreateRequest, CancellationToken cancellationToken) { try { var user = (Listinguser)HttpContext.Items["User"]; var listingModel = new Listing { Title = listingCreateRequest.Title, Description = listingCreateRequest.Description, Price = listingCreateRequest.Price, CreatorId = user.Id, CreatedDate = DateTime.UtcNow }; // listingCreateRequest.CreatorId = user.Id; // listingCreateRequest.CreatedDate = DateTime.UtcNow; Listing listing = await _unitOfWork.ListingRepository.PostAsync(listingModel); _unitOfWork.Commit(); return(CreatedAtAction( nameof(Post), new { Id = listing.Id }, listing)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); _unitOfWork.Rollback(); return(BadRequest()); } }
public Task <APIResponse <ListResult> > GetListingsAsync(string id, string[] except) { except = (except == null) ? new string[] { } : except; var par = new ListingRequest { searchId = id, except = except }; Task <APIResponse <ListResult> > response = api.CreateAsync <ListResult>( @"search.moreListings", par ); if (response.IsCompleted && response.Result != null) { if (response.Result.error != null) { using (var alert = new UIAlertView ("Make load error", string.Format("Please try again--{0}--Code:{1} ", response.Result.error.message, response.Result.error.code), null, "OK", null) ) { alert.Show(); } //we good TODO } } return(response); }
public ListResult GetListings(string id) { ListResult result = new ListResult(); var par = new ListingRequest { searchId = id, except = new string[] { } }; APIResponse <ListResult> response = api.CreateRequest <ListResult>( @"search.moreListings", par ); if (response != null) { if (response.error != null) { using (var alert = new UIAlertView("Make load error", string.Format("Please try again--{0}--Code:{1} ", response.error.message, response.error.code), null, "OK", null)) { alert.Show(); } //we good TODO } else if (response.Result != null) { result = response.Result; } } return(result); }
public async Task <Link> GetRandomLinkAsync(CancellationToken cancellationToken = default(CancellationToken)) { var request = new ListingRequest(); var listings = await Api.GetMultiListingAsync(string.Format(UrlConstants.SubredditRandomLinksUrl, Name), request, cancellationToken); return(listings.FirstOrDefault()?.OfType <Link>().FirstOrDefault()); }
public async Task <Listing> GetListingAsync(string url, ListingRequest request, CancellationToken cancellationToken = default(CancellationToken)) { Listing result = await GetAsync <Listing>(url, request, cancellationToken); result.Url = url; return(result); }
public async Task <IEnumerable <Listing> > GetListingsAsync(string regionSlug) { var request = new ListingRequest { RegionSlug = regionSlug }; var response = await GetAsync <ListingRequest, ListingResponse>(request); return(response.DataContainer.Listings.Select(dispensary => new Listing(dispensary.Slug, dispensary.Type))); }
public async void ShouldNotUpdateIfNotOwning(int id, string title, string description, decimal price, string createdDate) { // Arrange _controller.ControllerContext = Util.GetControllerContext(authenticatedUser); var updatedListing = new Listing { Id = id, Title = title, Description = description, Price = price, CreatorId = authenticatedUser.Id, CreatedDate = DateTime.Parse(createdDate) }; var updatedListingRequest = new ListingRequest { Title = updatedListing.Title, Description = updatedListing.Description, Price = updatedListing.Price, }; mockListingRepository .Setup(x => x.GetAsync(It.Is <string>(x => x == id.ToString()))) .ReturnsAsync(new Listing { Id = id, Title = "Current Title", Description = "Current Description", Price = price, CreatorId = authenticatedUser.Id + 1, CreatedDate = DateTime.Parse(createdDate) }); mockListingRepository .Setup(x => x.PutAsync( It.Is <string>(x => x == id.ToString()), updatedListing )) .ReturnsAsync(updatedListing); mockUnitOfWork .Setup(uow => uow.ListingRepository) .Returns(mockListingRepository.Object); // Act var result = await _controller.Put( id.ToString(), updatedListingRequest, cancellationToken); // Assert Assert.IsType <UnauthorizedResult>(result); Assert.Equal(401, (result as UnauthorizedResult).StatusCode); }
public static Task <Listing> GetPreviousListingAsync(this Listing listing, int limit, CancellationToken cancellationToken = default(CancellationToken)) { var request = new ListingRequest { Before = listing.Before, Limit = limit }; return(listing.Api.GetListingAsync(listing.Url, request, cancellationToken)); }
public static Task <Listing> GetNextListingAsync(this Listing listing, int limit, CancellationToken cancellationToken = default(CancellationToken)) { var request = new ListingRequest { After = listing.After, Limit = limit }; return(listing.Api.GetListingAsync(listing.Url, request, cancellationToken)); }
public async Task <List <Listing> > GetMultiListingAsync(string url, ListingRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var result = await GetAsync <List <Listing> >(url, request, cancellationToken); foreach (Listing listing in result) { listing.Url = url; } return(result); }
public async Task <Listing> GetAsync(int listingId, ListingRequest request) { Requires.ArgumentNotNull(request, nameof(request)); var root = await _halClient.GetRootAsync().ConfigureAwait(_halClient); var listingLink = new Link { HRef = $"{root.SelfLink.HRef}/listings/{listingId}" }; return(await _halClient.GetAsync <Listing>(listingLink, request).ConfigureAwait(_halClient)); }
public async Task <IReadOnlyList <Listing> > GetAllByEventAsync(int eventId, ListingRequest request) { Requires.ArgumentNotNull(request, nameof(request)); var root = await _halClient.GetRootAsync().ConfigureAwait(_halClient); var listingsLink = new Link { HRef = $"{root.SelfLink.HRef}/events/{eventId}/listings" }; return(await _halClient.GetAllPagesAsync <Listing>(listingsLink, request).ConfigureAwait(_halClient)); }
public async Task <IActionResult> GetAsync(int eventId, int page, int?numberOfTickets) { var listingRequest = new ListingRequest { Page = page, PageSize = PAGE_SIZE, NumberOfTickets = numberOfTickets }; var results = await ViagogoClient.Listings.GetByEventAsync(eventId, listingRequest); var items = results.Items.Select(TicketsListing.FromListing); return(new OkObjectResult(new { Page = page, TotalItems = results.TotalItems, Items = items.ToArray() })); }
public async Task <IActionResult> Put( string id, ListingRequest listingUpdateRequest, CancellationToken cancellationToken) { int idNum; if (!int.TryParse(id, out idNum)) { return(BadRequest()); } var user = (Listinguser)HttpContext.Items["User"]; try { Listing listing = await _unitOfWork.ListingRepository .GetAsync(id); if (listing == null || listing.CreatorId != user.Id) { return(Unauthorized()); } listing.Title = listingUpdateRequest.Title; listing.Description = listingUpdateRequest.Description; listing.Price = listingUpdateRequest.Price; // Since Listing is already tracked by GetAsync() above, // No need to call for PutAsync(). // Listing updatedListing = await _unitOfWork.ListingRepository // .PutAsync(id, listingUpdateRequest); _unitOfWork.Commit(); return(Ok(listing)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); _unitOfWork.Rollback(); return(BadRequest()); } }
/// <summary> /// <para>Returns the fees that will be charged for a listing once the auction or classified has been created. /// </para><para> /// There are several endpoints that should be used to get information needed to list an item. /// Check Category information, Legal Notice information, attributes, fees and listing duration options. /// </para> /// REQUIRES AUTHENTICATION. /// </summary> /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param> /// <returns>XDocument: FeeResponse</returns> public XDocument GetFeesForListingItems(ListingRequest request) { var query = String.Format(Constants.Culture, "{0}/{1}{2}", Constants.SELLING, Constants.FEES, Constants.XML); return(_connection.Post(request, query)); }
// Selling Methods: /// <summary> /// <para>Starts a new auction or classified. /// </para><para> /// There are several endpoints that should be used to get information needed to list an item. /// Check Category information, Legal Notice information, attributes, fees and listing duration options. /// </para> /// REQUIRES AUTHENTICATION. /// </summary> /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param> /// <returns>XDocument: ListingResponse</returns> public XDocument ListItem(ListingRequest request) { var query = String.Format(Constants.Culture, "{0}{1}", Constants.SELLING, Constants.XML); return(_connection.Post(request, query)); }
public Task <Listing> GetLinksById(ListingRequest request, IEnumerable <string> ids, CancellationToken cancellationToken = default(CancellationToken)) { return(GetListingAsync(string.Format(UrlConstants.LinksByIdUrl, string.Join(",", ids)), request, cancellationToken)); }
public Task <Listing> GetRisingLinksAsync(ListingRequest request, CancellationToken cancellationToken = default(CancellationToken)) { return(Api.GetListingAsync(string.Format(UrlConstants.SubredditRisingLinksUrl, Name), request, cancellationToken)); }
public async void ShouldCreateListing(string title, string description, decimal price) { // Arrange DateTime createdDate = DateTime.Now; _controller.ControllerContext = Util.GetControllerContext(authenticatedUser); var newListing = new Listing { Id = 0, Title = title, Description = description, Price = price, CreatorId = authenticatedUser.Id, CreatedDate = createdDate }; var newListingRequest = new ListingRequest { Title = newListing.Title, Description = newListing.Description, Price = newListing.Price, }; mockListingRepository .Setup(x => x.PostAsync( It.Is <Listing>(x => x.Title == newListing.Title && x.Description == newListing.Description && x.Price == newListing.Price && x.CreatorId == newListing.CreatorId ) )) .ReturnsAsync(newListing); mockUnitOfWork .Setup(uow => uow.ListingRepository) .Returns(mockListingRepository.Object); // Act var result = await _controller.Post( newListingRequest, cancellationToken); // Assert var createdResult = result as CreatedAtActionResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); Assert.IsType <Listing>(createdResult.Value); var valueResult = createdResult.Value as Listing; Assert.NotNull(valueResult); // Assert.Equal(newListing.Id, valueResult.Id); Assert.Equal(newListing.Title, valueResult.Title); Assert.Equal(newListing.Description, valueResult.Description); Assert.Equal(newListing.Price, valueResult.Price); Assert.Equal(newListing.CreatorId, valueResult.CreatorId); Assert.Equal(newListing.CreatedDate, valueResult.CreatedDate); }
public Task <Listing> GetFrontLinksAsync(ListingRequest request, CancellationToken cancellationToken = default(CancellationToken)) { return(GetListingAsync(UrlConstants.FrontUrl, request, cancellationToken)); }
// Selling Methods: /// <summary> /// <para>Starts a new auction or classified. /// </para><para> /// There are several endpoints that should be used to get information needed to list an item. /// Check Category information, Legal Notice information, attributes, fees and listing duration options. /// </para> /// REQUIRES AUTHENTICATION. /// </summary> /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param> /// <returns>XDocument: ListingResponse</returns> public XDocument ListItem(ListingRequest request) { var query = String.Format(Constants.Culture, "{0}{1}", Constants.SELLING, Constants.XML); return _connection.Post(request, query); }
// Selling Methods /// <summary> /// <para>Starts a new auction or classified. /// </para><para> /// There are several endpoints that should be used to get information needed to list an item. /// Check Category information, Legal Notice information, attributes, fees and listing duration options. /// </para> /// REQUIRES AUTHENTICATION. /// </summary> /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param> /// <returns>XDocument: ListingResponse</returns> public XDocument ListItem(ListingRequest request) { if (_selling == null) { _selling = new SellingMethods(_connection); } return _selling.ListItem(request); }
/// <summary> /// <para>Returns the fees that will be charged for a listing once the auction or classified has been created. /// </para><para> /// There are several endpoints that should be used to get information needed to list an item. /// Check Category information, Legal Notice information, attributes, fees and listing duration options. /// </para> /// REQUIRES AUTHENTICATION. /// </summary> /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param> /// <returns>XDocument: FeeResponse</returns> public XDocument GetFeesForListingItems(ListingRequest request) { if (_selling == null) { _selling = new SellingMethods(_connection); } return _selling.GetFeesForListingItems(request); }
public async void ShouldUpdateListingIfOwning(int id, string title, string description, decimal price, string createdDate) { // Arrange _controller.ControllerContext = Util.GetControllerContext(authenticatedUser); var updatedListing = new Listing { Id = id, Title = title, Description = description, Price = price, CreatorId = authenticatedUser.Id, CreatedDate = DateTime.Parse(createdDate) }; var updatedListingRequest = new ListingRequest { Title = updatedListing.Title, Description = updatedListing.Description, Price = updatedListing.Price, }; mockListingRepository .Setup(x => x.GetAsync(It.Is <string>(x => x == id.ToString()))) .ReturnsAsync(new Listing { Id = id, Title = "Current Title", Description = "Current Description", Price = price, CreatorId = authenticatedUser.Id, CreatedDate = DateTime.Parse(createdDate) }); mockListingRepository .Setup(x => x.PutAsync( It.Is <string>(x => x == id.ToString()), updatedListing )) .ReturnsAsync(updatedListing); mockUnitOfWork .Setup(uow => uow.ListingRepository) .Returns(mockListingRepository.Object); // Act var result = await _controller.Put( id.ToString(), updatedListingRequest, cancellationToken); // Assert var okResult = result as OkObjectResult; Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); var valueResult = okResult.Value as Listing; Assert.NotNull(valueResult); Assert.Equal(updatedListing.Id, valueResult.Id); Assert.Equal(updatedListing.Title, valueResult.Title); Assert.Equal(updatedListing.Description, valueResult.Description); Assert.Equal(updatedListing.Price, valueResult.Price); Assert.Equal(updatedListing.CreatorId, valueResult.CreatorId); Assert.Equal(updatedListing.CreatedDate, valueResult.CreatedDate); }
/// <summary> /// <para>Returns the fees that will be charged for a listing once the auction or classified has been created. /// </para><para> /// There are several endpoints that should be used to get information needed to list an item. /// Check Category information, Legal Notice information, attributes, fees and listing duration options. /// </para> /// REQUIRES AUTHENTICATION. /// </summary> /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param> /// <returns>XDocument: FeeResponse</returns> public XDocument GetFeesForListingItems(ListingRequest request) { var query = String.Format(Constants.Culture, "{0}/{1}{2}", Constants.SELLING, Constants.FEES, Constants.XML); return _connection.Post(request, query); }
public Task <Listing> GetNewSubredditsAsync(ListingRequest request, CancellationToken cancellationToken = default(CancellationToken)) { return(GetListingAsync(UrlConstants.NewSubredditsUrl, request, cancellationToken)); }