Ejemplo n.º 1
0
        public void ChangeConsumption(Consumption consumption)
        {
            if (!Type.ValidateConsumption(consumption))
            {
                throw new ArgumentException(nameof(consumption) + "の値が不正です");
            }

            this.Consumption = consumption;
        }
Ejemplo n.º 2
0
        public Material(MaterialId id,
                        MaterialName name,
                        MaterialType type,
                        TypeAndSize typesize,
                        Consumption consumption,
                        Length length,
                        Weight weight)
        {
            // 先にMaterialTypeがnullで無いことをチェックしないと、
            // 後続のValidationが出来なくなる。(Typeがnullなので、nullReferenceErrorとかになるはず)
            if (id == null)
            {
                throw new ArgumentException(nameof(MaterialId));
            }
            if (type == null)
            {
                throw new ArgumentException(nameof(MaterialType));
            }

            this.Id   = id;
            this.Type = type;

            if (!Type.ValidateName(name))
            {
                throw new ArgumentException(nameof(name));
            }
            if (!Type.ValidateLength(length))
            {
                throw new ArgumentException(nameof(Length));
            }
            if (!Type.ValidateWeight(weight))
            {
                throw new ArgumentException(nameof(Weight));
            }
            if (!Type.ValidateTypeAndSize(typesize))
            {
                throw new ArgumentException(nameof(typesize));
            }
            if (!Type.ValidateConsumption(consumption))
            {
                throw new ArgumentException(nameof(consumption));
            }

            this.Name        = name;
            this.Length      = length;
            this.Weight      = weight;
            this.TypeAndSize = typesize;
            this.Consumption = consumption;
        }
Ejemplo n.º 3
0
        public void Save(string id,
                         string name,
                         int materialTypeId,
                         string productType,
                         float?size,
                         float?consumption,
                         float?length,
                         float?weight)
        {
            var Id          = new MaterialId(id);
            var Name        = new MaterialName(name);
            var Type        = MaterialType.GetMaterialType(materialTypeId);
            var ProductType = new ProductType(productType);
            var Size        = new Size(size);
            var TypeAndSize = new TypeAndSize(ProductType, Size);
            var Consumption = new Consumption(consumption);
            var Length      = new Length(length);
            var Weight      = new Weight(weight);

            // 値個別のバリデーションは、エンティティを生成する時に行う
            var target = new Material(Id, Name, Type, TypeAndSize, Consumption, Length, Weight);

            var service = new MaterialService(repository);

            if (service.IsDuplicatedId(target.Id))
            {
                throw new Exception("IDが重複しています");
            }

            if (Type.Id == MaterialType.A.Id && service.IsOverAddedMaterialA())
            {
                throw new Exception("部材区分Aが2件登録されています");
            }

            if (Type.Id == MaterialType.B.Id && service.IsOverAddedTypeAndSize(TypeAndSize))
            {
                throw new Exception(nameof(TypeAndSize.Type.Value) + "と" +
                                    nameof(TypeAndSize.Size.Value) + "の組み合わせは2件登録されています");
            }

            repository.Save(target);
        }
Ejemplo n.º 4
0
 public override bool ValidateConsumption(Consumption consumption)
 {
     // 部材Bではチェックしない
     return(true);
 }
Ejemplo n.º 5
0
 public override bool ValidateConsumption(Consumption consumption)
 {
     return(consumption.Value != null);
 }
Ejemplo n.º 6
0
 // バリデーションメソッドを抽象メソッドとして用意しておく
 public abstract bool ValidateConsumption(Consumption consumption);