public void SetPercentageToCompoundWithCompoundIdInto(BusinessMatrix matrixGroup, int compoundId)
        {
            var percentageToCompound = from item in this.PercentToCompoundRepository.GetAllWithCompountId(compoundId)
                                       where item.PercentId == matrixGroup.Percentage.Id
                                       select item;

            if (percentageToCompound.Count() > 0)
            {
                matrixGroup.PercentToCompound = percentageToCompound.ToArray()[0];
            }
            else
            {
                matrixGroup.PercentToCompound = new PercentToCompound(matrixGroup.Percentage.Id, compoundId);
            }
        }
        public void SetMatrixWithIdInto(BusinessMatrix matrixGroup, int id)
        {
            var matrix = this.MatrixRepository.GetMatrixById(id);

            if (matrix == null)
            {
                throw new ArgumentException(string.Format("Matrix with Id = {0} was not found in database.", id));
            }

            matrixGroup.Matrix = matrix;

            if (matrixGroup.Percentage.Number > 0)
            {
                SetPercentageWiyhNumberInto(matrixGroup, matrixGroup.Percentage.Number);
            }
        }
        public void SetPercentageWiyhNumberInto(BusinessMatrix matrixGroup, double number)
        {
            if (number < 0)
            {
                throw new ArgumentException("Percentage number should be bigger that zero.");
            }

            var percentage = this.PercentageRepository.GetPercentageWithValues(number, matrixGroup.Matrix.Id, null);

            if (percentage != null)
            {
                percentage = new Percentage(-1, number, null, matrixGroup.Matrix.Id);
            }

            matrixGroup.Percentage = percentage;

            if (matrixGroup.PercentToCompound.CompoundId > 0)
            {
                SetPercentageToCompoundWithCompoundIdInto(matrixGroup, matrixGroup.PercentToCompound.CompoundId);
            }
        }