// 製品種類とサイズの組み合わせが2件以上登録されているか public bool IsOverAddedTypeAndSize(TypeAndSize typeAndWidth) { // 製品種類とサイズの組み合わせが登録されているのは部材区分Bのみ var materials = repository.Find(MaterialType.B); var count = materials.Count(x => x.TypeAndSize.Equals(typeAndWidth)); return(count >= 2); }
public void ChangeSize(Size size) { var value = new TypeAndSize(this.TypeAndSize.Type, size); if (!Type.ValidateTypeAndSize(value)) { throw new ArgumentException(nameof(size) + "の値が不正です"); } this.TypeAndSize = value; }
public void ChangeType(ProductType type) { var value = new TypeAndSize(type, this.TypeAndSize.Size); if (!Type.ValidateTypeAndSize(value)) { throw new ArgumentException(nameof(type) + "の値が不正です"); } this.TypeAndSize = value; }
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; }
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); }
public override bool ValidateTypeAndSize(TypeAndSize typesize) { bool validateOk = (typesize.Size.Value != null && typesize.Type.Value != null); return(validateOk); }
public override bool ValidateTypeAndSize(TypeAndSize typesize) { // 部材Aでは特にチェックしない return(true); }
public abstract bool ValidateTypeAndSize(TypeAndSize typesize);