Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public virtual coreModel.Pricelist CreatePricelist(coreModel.Pricelist priceList)
        {
            var entity = priceList.ToDataModel();

            using (var repository = _repositoryFactory())
            {
                repository.Add(entity);
                CommitChanges(repository);
            }

            return(GetPricelistById(entity.Id));
        }
		/// <summary>
		/// Converting to model type
		/// </summary>
		/// <param name="catalogBase"></param>
		/// <returns></returns>
		public static coreModel.Pricelist ToCoreModel(this dataModel.Pricelist dbEntity)
		{
			if (dbEntity == null)
				throw new ArgumentNullException("dbEntity");

			var retVal = new coreModel.Pricelist();
			retVal.InjectFrom(dbEntity);
			retVal.Currency = dbEntity.Currency;
			retVal.Prices = dbEntity.Prices.Select(x => x.ToCoreModel()).ToList();
		
			return retVal;

		}
Ejemplo n.º 4
0
		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;
		}
Ejemplo n.º 5
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="catalogBase"></param>
        /// <returns></returns>
        public static coreModel.Pricelist ToCoreModel(this dataModel.Pricelist dbEntity)
        {
            if (dbEntity == null)
            {
                throw new ArgumentNullException("dbEntity");
            }

            var retVal = new coreModel.Pricelist();

            retVal.InjectFrom(dbEntity);
            retVal.Currency = (CurrencyCodes)Enum.Parse(typeof(CurrencyCodes), dbEntity.Currency);
            retVal.Prices   = dbEntity.Prices.Select(x => x.ToCoreModel()).ToList();

            return(retVal);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public virtual coreModel.Pricelist GetPricelistById(string id)
        {
            coreModel.Pricelist retVal = null;

            using (var repository = _repositoryFactory())
            {
                var entity = repository.GetPricelistById(id);

                if (entity != null)
                {
                    retVal = entity.ToCoreModel();

                    var assignments = repository.GetAllPricelistAssignments(id);
                    retVal.Assignments = assignments.Select(x => x.ToCoreModel()).ToList();
                }
            }

            return(retVal);
        }
Ejemplo n.º 8
0
        public static dataModel.Pricelist ToDataModel(this coreModel.Pricelist priceList)
        {
            if (priceList == null)
            {
                throw new ArgumentNullException("priceList");
            }

            var retVal = new dataModel.Pricelist();

            retVal.InjectFrom(priceList);
            retVal.Currency = priceList.Currency.ToString();

            retVal.Prices = new NullCollection <dataModel.Price>();
            if (priceList.Prices != null)
            {
                retVal.Prices = new ObservableCollection <dataModel.Price>(priceList.Prices.Select(x => x.ToDataModel()));
            }

            return(retVal);
        }
Ejemplo n.º 9
0
        public virtual coreModel.Price CreatePrice(coreModel.Price price)
        {
            var entity = price.ToDataModel();

            using (var repository = _repositoryFactory())
            {
                //Need assign price to default pricelist with same currency or create it if not exist
                if (price.PricelistId == null)
                {
                    var defaultPriceListId = GetDefaultPriceListName(price.Currency);
                    var dbDefaultPriceList = repository.GetPricelistById(defaultPriceListId);

                    if (dbDefaultPriceList == null)
                    {
                        var defaultPriceList = new coreModel.Pricelist
                        {
                            Id          = defaultPriceListId,
                            Currency    = price.Currency,
                            Name        = defaultPriceListId,
                            Description = defaultPriceListId
                        };
                        dbDefaultPriceList = defaultPriceList.ToDataModel();
                    }
                    entity.PricelistId = dbDefaultPriceList.Id;
                    entity.Pricelist   = dbDefaultPriceList;

                    repository.Add(entity);

                    CommitChanges(repository);
                    //Automatically create catalog assignment
                    TryToCreateCatalogAssignment(entity, repository);
                    ResetCache();
                }
            }
            price.Id = entity.Id;
            var retVal = GetPriceById(entity.Id);

            return(retVal);
        }
Ejemplo n.º 10
0
        public virtual coreModel.Price CreatePrice(coreModel.Price price)
        {
            var entity = price.ToDataModel();

			using (var repository = _repositoryFactory())
			{
				//Need assign price to default pricelist with same currency or create it if not exist
				if (price.PricelistId == null)
				{
					var defaultPriceListId = GetDefaultPriceListName(price.Currency);
					var dbDefaultPriceList = repository.GetPricelistById(defaultPriceListId);

					if (dbDefaultPriceList == null)
					{
						var defaultPriceList = new coreModel.Pricelist
						{
							Id = defaultPriceListId,
							Currency = price.Currency,
							Name = defaultPriceListId,
							Description = defaultPriceListId
						};
						dbDefaultPriceList = defaultPriceList.ToDataModel();
					}
					entity.PricelistId = dbDefaultPriceList.Id;
					entity.Pricelist = dbDefaultPriceList;

					repository.Add(entity);
				
					CommitChanges(repository);
					//Automatically create catalog assignment 
					TryToCreateCatalogAssignment(entity, repository);
				}

			}
			price.Id = entity.Id;
			var retVal = GetPriceById(entity.Id);
            return retVal;
        }