public async Task <CustomResponse> Get(Guid id) { ItemDto item = await _unitOfWork.ItemRepository.FindAsync(id); if (item == null) { return(_responsMessages.ItemNotFound); } GetItemModel model = _mapper.Map <GetItemModel>(item); return(new OkResponse(model)); }
/// <summary> /// Gets an image and a character name for an item. SKU doesn't actually seem to exist in the API /// </summary> /// <param name="legacyItemId"></param> /// <param name="legacyVariationId"></param> /// <returns></returns> public GetItemModel GetItem(string legacyItemId, string legacyVariationId) { if (string.IsNullOrEmpty(legacyVariationId)) { legacyVariationId = "0"; } string response; try { response = _service.GetRequest($"https://api.ebay.com/buy/browse/v1/item/v1|{legacyItemId}|{legacyVariationId}"); } catch (ApiException) { return(new GetItemModel { Character = "", Image = "" }); } var obj = JsonConvert.DeserializeObject <GetItemResponse>(response); var character = ""; var sku = ""; foreach (var aspect in obj.localizedAspects) { if (aspect.name == "Character") { character = aspect.value; } else if (aspect.name == "SKU") { sku = aspect.value; } } var model = new GetItemModel { Character = character, Image = obj.image.imageUrl, SKU = sku }; _dataService.UpdateOrderItemsByLegacyId(legacyItemId, legacyVariationId, model); return(model); }
/// <summary> /// Loads more info for order items into the db /// </summary> /// <param name="legacyItemId"></param> /// <param name="legacyVariationId"></param> /// <param name="model"></param> public void UpdateOrderItemsByLegacyId(string legacyItemId, string legacyVariationId, GetItemModel model) { var items = _orderItemRepo.Find(x => x.LegacyItemId == legacyItemId && x.LegacyVariationId == legacyVariationId).ToList(); foreach (var item in items) { item.Image = model.Image; item.CharacterName = model.Character; _orderItemRepo.Update(item); } }