Esempio n. 1
0
        public void ChangeName(MaterialName name)
        {
            if (!Type.ValidateName(name))
            {
                throw new ArgumentException(nameof(name) + "の値が不正です");
            }

            this.Name = name;
        }
Esempio 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;
        }
Esempio 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);
        }
Esempio n. 4
0
 public override bool ValidateName(MaterialName name)
 {
     return(name.Value != null);
 }
Esempio n. 5
0
 public abstract bool ValidateName(MaterialName name);