/// <summary>
		/// Gets all Bricklink colours. If they aren't in the DB, get them from the API.
		/// </summary>
		/// <returns>Every colour in a model</returns>
		public IEnumerable<ColourModel> GetAll()
		{
			using (var repo = new BaseRepository<Colour>())
			{
				var colours = repo.FindAll();

				if (!colours.Any())
				{
					var apiService = new BricklinkApiService();
					var result = apiService.GetRequest<GetColoursResponse>("/colors");

					colours = result.data.Select(x => repo.Add(new Colour
					{
						ColourId = x.color_id,
						ColourCode = x.color_code,
						ColourType = x.color_type,
						Name = x.color_name
					}));
				}

				return colours.Select(x => new ColourModel(x));
			}
		}
Exemplo n.º 2
0
        /// <summary>
        /// Gets a list of orders of a status. No order details
        /// </summary>
        /// <param name="status">Status to search for</param>
        /// <returns>Model - list of orders, also status</returns>
        public OrdersModel GetOrders(string status)
        {
            var result = _apiService.GetRequest($"orders?direction=in&status={status.ToUpper()}");

            var responseModel = JsonConvert.DeserializeObject <GetOrdersResponseModel>(result);

            var model = new OrdersModel(responseModel, status);

            foreach (var order in model.Orders)
            {
                var orderEntity = _dataService.GetOrder(order.OrderId) as Data.Entities.BricklinkOrder;

                if (orderEntity != null)
                {
                    order.RealName = orderEntity.BuyerRealName;
                }
            }

            return(model);
        }