public void UpdateLocales(QuantityUnit quantityUnit, QuantityUnitModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(quantityUnit, x => x.Name, localized.Name, localized.LanguageId);
         _localizedEntityService.SaveLocalizedValue(quantityUnit, x => x.Description, localized.Description, localized.LanguageId);
     }
 }
        /// <summary>
        /// Deletes QuantityUnit
        /// </summary>
        /// <param name="quantityUnit">QuantityUnit</param>
        public virtual void DeleteQuantityUnit(QuantityUnit quantityUnit)
        {
            if (quantityUnit == null)
                throw new ArgumentNullException("quantityUnit");

            if (this.IsAssociated(quantityUnit.Id))
                throw new SmartException("The quantity unit cannot be deleted. It has associated product variants");

            _quantityUnitRepository.Delete(quantityUnit);

            _cacheManager.RemoveByPattern(MEASUREUNITS_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityDeleted(quantityUnit);
        }
Пример #3
0
		protected virtual void WriteQuantityUnit(XmlWriter writer, XmlExportContext context, QuantityUnit quantityUnit)
		{
			if (quantityUnit != null)
			{
				writer.WriteStartElement("QuantityUnit");
				writer.Write("Id", quantityUnit.Id.ToString());
				writer.Write("Name", quantityUnit.Name);
				writer.Write("Description", quantityUnit.Description);
				writer.Write("DisplayLocale", quantityUnit.DisplayLocale);
				writer.Write("DisplayOrder", quantityUnit.DisplayOrder.ToString());
				writer.Write("IsDefault", quantityUnit.IsDefault.ToString());
				WriteLocalized(writer, context, lang =>
				{
					writer.Write("Name", quantityUnit.GetLocalized(x => x.Name, lang.Id, false, false), lang);
					writer.Write("Description", quantityUnit.GetLocalized(x => x.Description, lang.Id, false, false), lang);
				});
				writer.WriteEndElement();
			}
		}
        /// <summary>
        /// Updates the QuantityUnit
        /// </summary>
        /// <param name="quantityUnit">QuantityUnit</param>
        public virtual void UpdateQuantityUnit(QuantityUnit quantityUnit)
        {
            if (quantityUnit == null)
                throw new ArgumentNullException("quantityUnit");

            if (quantityUnit.IsDefault == true) {

                var temp = new List<QuantityUnit>();
                temp.Add(quantityUnit);

                var query = GetAllQuantityUnits()
                    .Where(x => x.IsDefault == true)
                    .Except(temp);
                
                foreach(var qu in query) 
                {
                    qu.IsDefault = false;
                    _quantityUnitRepository.Update(qu);
                }
            }

            _quantityUnitRepository.Update(quantityUnit);

            _cacheManager.RemoveByPattern(MEASUREUNITS_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityUpdated(quantityUnit);
        }
        /// <summary>
        /// Inserts a QuantityUnit
        /// </summary>
        /// <param name="quantityUnit">QuantityUnit</param>
        public virtual void InsertQuantityUnit(QuantityUnit quantityUnit)
        {
            if (quantityUnit == null)
                throw new ArgumentNullException("quantityUnit");

            _quantityUnitRepository.Insert(quantityUnit);

            _cacheManager.RemoveByPattern(MEASUREUNITS_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityInserted(quantityUnit);
        }
 public static QuantityUnit ToEntity(this QuantityUnitModel model, QuantityUnit destination)
 {
     return Mapper.Map(model, destination);
 }