public static TaxRegimeTypeViewModel FromDto(TaxRegimeDto taxRegimeType) => new TaxRegimeTypeViewModel() { Id = taxRegimeType.Id, Name = taxRegimeType.Name, Description = taxRegimeType.Description };
Either <Error, TaxRegimeDto> ValidateIsCorrectUpdate(long id, TaxRegimeDto taxRegimeDto) { if (id == taxRegimeDto.Id) { return(taxRegimeDto); } return(Error.New("Invalid update entity id")); }
Either <Error, TaxRegimeType> UpdateEntity(TaxRegimeDto taxRegimeDto, TaxRegimeType taxRegime) { taxRegime.EditTaxRegimeType(new Name(taxRegimeDto.Name), new GeneralText(taxRegimeDto.Description)); return(taxRegime); }
Either <Error, TaxRegimeType> CreateEntity(TaxRegimeDto taxRegimeDto) => Right <Error, TaxRegimeType>(taxRegimeDto);
Either <Error, TaxRegimeDto> ValidateName(TaxRegimeDto taxRegimeDto) => Name.Of(taxRegimeDto.Name).Match(Succ: c => taxRegimeDto, Fail: err => Left <Error, TaxRegimeDto>(Error.New(string.Join(";", err))));
public Either <Error, TaxRegimeType> Update(long id, TaxRegimeDto taxDto) => ValidateIsCorrectUpdate(id, taxDto) .Bind(ValidateName) .Bind(c => Find(c.Id)) .Bind(c => UpdateEntity(taxDto, c)) .Bind(Save);
public Either <Error, TaxRegimeType> Create(TaxRegimeDto taxRegimeDto) => ValidateName(taxRegimeDto) .Bind(CreateEntity) .Bind(Add) .Bind(Save);