public MeasureDimension SaveInfo() { string name = txtName.Text; string systemKeyword = txtSystemKeyword.Text; decimal ratio = txtRatio.Value; int displayOrder = txtDisplayOrder.Value; MeasureDimension measureDimension = this.MeasureService.GetMeasureDimensionById(this.MeasureDimensionId); if (measureDimension != null) { measureDimension.Name = name; measureDimension.SystemKeyword =systemKeyword; measureDimension.Ratio =ratio; measureDimension.DisplayOrder =displayOrder; this.MeasureService.UpdateMeasureDimension(measureDimension); } else { measureDimension = new MeasureDimension() { Name = name, SystemKeyword = systemKeyword, Ratio = ratio, DisplayOrder = displayOrder }; this.MeasureService.InsertMeasureDimension(measureDimension); } return measureDimension; }
private static MeasureDimension DBMapping(DBMeasureDimension dbItem) { if (dbItem == null) return null; MeasureDimension item = new MeasureDimension(); item.MeasureDimensionID = dbItem.MeasureDimensionID; item.Name = dbItem.Name; item.SystemKeyword = dbItem.SystemKeyword; item.DisplayOrder = dbItem.DisplayOrder; return item; }
/// <summary> /// Updates the measure dimension /// </summary> /// <param name="measure">Measure dimension</param> public void UpdateMeasureDimension(MeasureDimension measure) { if (measure == null) throw new ArgumentNullException("measure"); measure.Name = CommonHelper.EnsureNotNull(measure.Name); measure.Name = CommonHelper.EnsureMaximumLength(measure.Name, 100); measure.SystemKeyword = CommonHelper.EnsureNotNull(measure.SystemKeyword); measure.SystemKeyword = CommonHelper.EnsureMaximumLength(measure.SystemKeyword, 100); if (!_context.IsAttached(measure)) _context.MeasureDimensions.Attach(measure); _context.SaveChanges(); if (this.CacheEnabled) { _cacheManager.RemoveByPattern(MEASUREDIMENSIONS_PATTERN_KEY); } }
/// <summary> /// Converts to primary measure dimension /// </summary> /// <param name="quantity">Quantity</param> /// <param name="sourceMeasureDimension">Source dimension</param> /// <returns>Converted value</returns> public decimal ConvertToPrimaryMeasureDimension(decimal quantity, MeasureDimension sourceMeasureDimension) { decimal result = quantity; if (result != decimal.Zero && sourceMeasureDimension.MeasureDimensionId != BaseDimensionIn.MeasureDimensionId) { decimal exchangeRatio = sourceMeasureDimension.Ratio; if (exchangeRatio == decimal.Zero) throw new NopException(string.Format("Exchange ratio not set for dimension [{0}]", sourceMeasureDimension.Name)); result = result / exchangeRatio; } return result; }
/// <summary> /// Converts dimension /// </summary> /// <param name="quantity">Quantity</param> /// <param name="sourceMeasureDimension">Source dimension</param> /// <param name="targetMeasureDimension">Target dimension</param> /// <returns>Converted value</returns> public decimal ConvertDimension(decimal quantity, MeasureDimension sourceMeasureDimension, MeasureDimension targetMeasureDimension) { decimal result = quantity; if (sourceMeasureDimension.MeasureDimensionId == targetMeasureDimension.MeasureDimensionId) return result; if (result != decimal.Zero && sourceMeasureDimension.MeasureDimensionId != targetMeasureDimension.MeasureDimensionId) { result = ConvertToPrimaryMeasureDimension(result, sourceMeasureDimension); result = ConvertFromPrimaryMeasureDimension(result, targetMeasureDimension); } result = Math.Round(result, 2); return result; }
/// <summary> /// Converts dimension /// </summary> /// <param name="quantity">Quantity</param> /// <param name="sourceMeasureDimension">Source dimension</param> /// <param name="targetMeasureDimension">Target dimension</param> /// <returns>Converted value</returns> public static decimal ConvertDimension(decimal quantity, MeasureDimension sourceMeasureDimension, MeasureDimension targetMeasureDimension) { decimal result = quantity; if (sourceMeasureDimension.MeasureDimensionId == targetMeasureDimension.MeasureDimensionId) { return(result); } if (result != decimal.Zero && sourceMeasureDimension.MeasureDimensionId != targetMeasureDimension.MeasureDimensionId) { result = ConvertToPrimaryMeasureDimension(result, sourceMeasureDimension); result = ConvertFromPrimaryMeasureDimension(result, targetMeasureDimension); } result = Math.Round(result, 2); return(result); }