public static webModel.Pricelist ToWebModel(this coreModel.Pricelist priceList, coreCatalogModel.CatalogProduct[] products = null, coreCatalogModel.Catalog[] catalogs = null, ConditionExpressionTree etalonEpressionTree = null)
        {
            var retVal = new webModel.Pricelist();

            retVal.InjectFrom(priceList);
            retVal.Currency = priceList.Currency;
            if (priceList.Prices != null)
            {
                retVal.ProductPrices = new List <webModel.ProductPrice>();
                foreach (var group in priceList.Prices.GroupBy(x => x.ProductId))
                {
                    var productPrice = new webModel.ProductPrice(group.Key, group.Select(x => x.ToWebModel()));

                    retVal.ProductPrices.Add(productPrice);
                    if (products != null)
                    {
                        var product = products.FirstOrDefault(x => x.Id == productPrice.ProductId);
                        if (product != null)
                        {
                            productPrice.ProductName = product.Name;
                        }
                    }
                }
            }
            if (priceList.Assignments != null)
            {
                retVal.Assignments = priceList.Assignments.Select(x => x.ToWebModel(catalogs, etalonEpressionTree)).ToList();
            }
            return(retVal);
        }
        public IHttpActionResult CreatePriceList(webModel.Pricelist priceList)
        {
            var pricelist = _pricingService.CreatePricelist(priceList.ToCoreModel());
            var result    = pricelist.ToWebModel();

            return(Ok(result));
        }
		public static webModel.Pricelist ToWebModel(this coreModel.Pricelist priceList, coreCatalogModel.CatalogProduct[] products = null, coreCatalogModel.Catalog[] catalogs = null, ConditionExpressionTree etalonEpressionTree = null)
		{
			var retVal = new webModel.Pricelist();
			retVal.InjectFrom(priceList);
			retVal.Currency = priceList.Currency;
			if (priceList.Prices != null)
			{
				retVal.ProductPrices = new List<webModel.ProductPrice>();
				foreach(var group in priceList.Prices.GroupBy(x=>x.ProductId))
				{
					var productPrice = new webModel.ProductPrice(group.Key, group.Select(x=> x.ToWebModel()));
					
					retVal.ProductPrices.Add(productPrice);
					if (products != null)
					{
						var product = products.FirstOrDefault(x => x.Id == productPrice.ProductId);
						if(product != null)
						{
							productPrice.ProductName = product.Name;
						}
					}
				}
				
			}
			if(priceList.Assignments != null)
			{
				retVal.Assignments = priceList.Assignments.Select(x => x.ToWebModel(catalogs, etalonEpressionTree)).ToList();
			}
			return retVal;
		}
        public IHttpActionResult GetPriceListById(string id)
        {
            webModel.Pricelist result = null;
            var pricelist             = _pricingService.GetPricelistById(id);

            if (pricelist != null)
            {
                var productIds = pricelist.Prices.Select(x => x.ProductId).Distinct().ToArray();
                var products   = _itemService.GetByIds(productIds, Domain.Catalog.Model.ItemResponseGroup.ItemInfo);
                var catalogs   = _catalogService.GetCatalogsList().ToArray();
                result = pricelist.ToWebModel(products, catalogs, _extensionManager.ConditionExpressionTree);
            }
            return(result != null?Ok(result) : (IHttpActionResult)NotFound());
        }
        public static coreModel.Pricelist ToCoreModel(this webModel.Pricelist priceList)
        {
            var retVal = new coreModel.Pricelist();

            retVal.InjectFrom(priceList);
            retVal.Currency = priceList.Currency;
            if (priceList.ProductPrices != null)
            {
                retVal.Prices = priceList.ProductPrices.SelectMany(x => x.Prices).Select(x => x.ToCoreModel()).ToList();
            }
            if (priceList.Assignments != null)
            {
                retVal.Assignments = priceList.Assignments.Select(x => x.ToCoreModel()).ToList();
            }
            return(retVal);
        }
        public IHttpActionResult UpdateProductPriceLists(string productId, webModel.Pricelist priceList)
        {
            var product           = _itemService.GetById(productId, Domain.Catalog.Model.ItemResponseGroup.ItemInfo);   //todo check uses
            var originalPriceList = _pricingService.GetPricelistById(priceList.Id);

            if (originalPriceList != null)
            {
                //Clean product prices in original pricelist
                var productPrices = originalPriceList.Prices.Where(x => x.ProductId == productId).ToArray();
                foreach (var productPrice in productPrices)
                {
                    originalPriceList.Prices.Remove(productPrice);
                }

                //Add changed prices to original pricelist
                originalPriceList.Prices.AddRange(priceList.ToCoreModel().Prices);
                _pricingService.UpdatePricelists(new [] { originalPriceList });
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public IHttpActionResult UpdatePriceList(webModel.Pricelist priceList)
 {
     _pricingService.UpdatePricelists(new [] { priceList.ToCoreModel() });
     return(StatusCode(HttpStatusCode.NoContent));
 }