private void ValidateOpenState() { if (State == PurchaseState.Closed) { throw ExceptionsFactory.FactoryDomainException(Messages.RegisterClosedNotMoviment); } }
private void ValidateIfNotExistsItem(OutputItem item) { if (ExistsItem(item) is false) { throw ExceptionsFactory.FactoryNotFoundException <Output>(item.Id); } }
public void CopyFile(string from, string to) { from = RebasePath(from); to = RebasePath(to); if (!File.Exists(from)) { throw ExceptionsFactory.PathNotExist(from); } if (File.Exists(to)) { while (true) { var response = _messenger.Confirm("Output file already exist, rewrite it? (y,n): "); if (!response) { throw ExceptionsFactory.SamePathAlreadyExist(to, nameof(to)); } break; } File.Copy(from, to, true); } var copyDirectory = Path.GetDirectoryName(to); if (!Directory.Exists(copyDirectory)) { Directory.CreateDirectory(copyDirectory); } File.Copy(from, to); }
public void ChangeDirectory(DirectoryMove move, string path = null) { switch (move) { case DirectoryMove.Back: var backDir = CurrentDirectory.Parent; ChangeDirectory(backDir); break; case DirectoryMove.ToRoot: var root = Path.GetPathRoot(CurrentDirectoryPath); ChangeDirectory(new DirectoryInfo(root)); break; case DirectoryMove.Inner when path is not null: var next = Path.Combine(CurrentDirectoryPath, path); if (!Path.IsPathFullyQualified(next)) { throw ExceptionsFactory.PathNotExist(next); } ChangeDirectory(next); break; default: throw new ArgumentOutOfRangeException(nameof(move), move, null); } OnDirectoryChanged?.Invoke(); }
/// <summary> /// Method responsible for update data. /// </summary> /// <param name="id"></param> /// <param name="data"></param> /// <returns></returns> /// <exception cref="Core.DomainObjects.Exceptions.NotFoundException"></exception> /// <exception cref="ApplicationException"></exception> public async Task <ApplicationDataResult <ProductDto> > UpdateASync(Guid id, AddOrUpdateProductDto data) { ValidationResult validationResult = await _validatorProduct.ValidateAsync(data); if (validationResult.IsValid is false) { return(FactoryFromValidationResult <ProductDto>(validationResult)); } Product product = await _productRepository.FindAsync(id); if (product is null) { throw ExceptionsFactory.FactoryNotFoundException <Product>(id); } Product result = await _productRepository.FindAsync(new ProductFilter { Description = data.Description }); if (result != null && result.Id != id) { throw ExceptionsFactory.FactoryApplicationException(ErrorMessages.ProductFound); } product.Update(data.Description, data.IsActive); _productRepository.Update(product); await _productRepository.UnitOfWork.CommitAsync(); return(FactoryResultFromData(_mapper.Map <ProductDto>(product))); }
public static void ValidarSeMaiorQue(DateTime valor, DateTime minimo, string mensagem) { if (valor > minimo) { throw ExceptionsFactory.FactoryDomainException(mensagem); } }
private void ValidateIfNotExistsItem(PurchaseItem item) { if (ExistsItem(item) is false) { throw ExceptionsFactory.FactoryNotFoundException <Purchase>(item.Id); } }
public static void ValidarSeIgual(object object1, object object2, string mensagem) { if (object1.Equals(object2)) { throw ExceptionsFactory.FactoryDomainException(mensagem); } }
public static void ValidarMinimoMaximo(long valor, long minimo, long maximo, string mensagem) { if (valor < minimo || valor > maximo) { throw ExceptionsFactory.FactoryDomainException(mensagem); } }
private void ValidateDuplicatedItem(PurchaseItem item) { if (ExistsItem(item) is true) { throw ExceptionsFactory.FactoryDomainException(Messages.ItemFound); } }
public static void ValidarSeNulo(object object1, string mensagem) { if (object1 == null) { throw ExceptionsFactory.FactoryDomainException(mensagem); } }
private void ValidateDuplicatedProduct(PurchaseItem item) { if (ExistsProduct(item.Product) is true) { throw ExceptionsFactory.FactoryDomainException(Messages.ProductFound); } }
public static void ValidarSeVerdadeiro(bool boolvalor, string mensagem) { if (boolvalor) { throw ExceptionsFactory.FactoryDomainException(mensagem); } }
public static void ValidarSeVazio(string valor, string mensagem) { if (valor == null || valor.Trim().Length == 0) { throw ExceptionsFactory.FactoryDomainException(mensagem); } }
public async Task <ApplicationDataResult <PurchaseItemDto> > UpdateItemAsync(Guid purchaseId, Guid purchaseItemId, AddOrUpdatePurchaseItemDto data) { ValidationResult validationResult = await _validatorPurchaseItem.ValidateAsync(data); if (validationResult.IsValid is false) { return(FactoryFromValidationResult <PurchaseItemDto>(validationResult)); } Purchase purchase = await _purchaseRepository.FindAsync(purchaseId); PurchaseItem purchaseItem = purchase.FindItemById(purchaseItemId); if (purchaseItem is null) { throw ExceptionsFactory.FactoryNotFoundException <PurchaseItem>(purchaseItemId); } Product product = await _productRepository.FindAsync(data.ProductId); if (product is null) { throw ExceptionsFactory.FactoryNotFoundException <Product>(purchaseId); } purchaseItem.Update(data.Amount, data.Value, product); await _purchaseService.UpdateItemAsync(purchase, purchaseItem); return(FactoryResultFromData(_mapper.Map <PurchaseItemDto>(purchaseItem))); }
public static void ValidarSeMenorQue(int valor, int minimo, string mensagem) { if (valor < minimo) { throw ExceptionsFactory.FactoryDomainException(mensagem); } }
public override bool CanHandle(string[] args) { if (args.Length != 1) { throw ExceptionsFactory.IncorrectArgument("Path to delete", nameof(args)); } return(Path.IsPathFullyQualified(args[0])); }
public static void ValidarTamanho(string valor, int minimo, int maximo, string mensagem) { var length = valor.Trim().Length; if (length < minimo || length > maximo) { throw ExceptionsFactory.FactoryDomainException(mensagem); } }
public static void ValidarSeDiferente(string pattern, string valor, string mensagem) { var regex = new Regex(pattern); if (!regex.IsMatch(valor)) { throw ExceptionsFactory.FactoryDomainException(mensagem); } }
public void Close() { if (State == PurchaseState.Closed) { throw ExceptionsFactory.FactoryDomainException(Messages.RegisterClosed); } State = PurchaseState.Closed; }
public bool StringPathIsDirectory(string path) { if (path is null) { throw ExceptionsFactory.IncorrectArgument("Path to file or directory", nameof(path)); } var pathToCheck = Path.IsPathRooted(path) ? path : Path.Combine(CurrentDirectoryPath, path); var attributes = File.GetAttributes(pathToCheck); return(attributes.HasFlag(FileAttributes.Directory)); }
public async Task <PurchaseItemDto> FindItemAsync(Guid purchaseId, Guid purchaseItemId) { Purchase purchase = await _purchaseRepository.FindAsync(purchaseId); if (purchase is null) { throw ExceptionsFactory.FactoryNotFoundException <Purchase>(purchaseId); } return(_mapper.Map <PurchaseItemDto>(purchase.FindItemById(purchaseItemId))); }
public async Task CloseAsync(Guid purchaseId) { Purchase purchase = await _purchaseRepository.FindAsync(purchaseId); if (purchase is null) { throw ExceptionsFactory.FactoryNotFoundException <Purchase>(purchaseId); } await _purchaseService.CloseAsync(purchase); }
public async Task <IList <PurchaseItemDto> > FindItensAsync(Guid purchaseId) { Purchase purchase = await _purchaseRepository.FindAsync(purchaseId); if (purchase is null) { throw ExceptionsFactory.FactoryNotFoundException <Purchase>(purchaseId); } return(_mapper.Map <IList <PurchaseItemDto> >(purchase.Items)); }
/// <summary> /// Method responsible for remove data. /// </summary> /// <param name="id"></param> /// <returns></returns> /// <exception cref="Core.DomainObjects.Exceptions.NotFoundException"></exception> public async Task RemoveASync(Guid id) { Product product = await _productRepository.FindAsync(id); if (product is null) { throw ExceptionsFactory.FactoryNotFoundException <Product>(id); } _productRepository.Remove(product); await _productRepository.UnitOfWork.CommitAsync(); }
public async Task RemoveAsync(Guid purchaseId) { Purchase purchase = await _purchaseRepository.FindAsync(purchaseId); if (purchase is null) { throw ExceptionsFactory.FactoryNotFoundException <Purchase>(purchaseId); } _purchaseRepository.Remove(purchase); await _purchaseRepository.UnitOfWork.CommitAsync(); }
public void CopyDirectory(string from, string to) { from = RebasePath(from); to = RebasePath(to); if (!Directory.Exists(from)) { throw ExceptionsFactory.PathNotExist(from); } if (!Directory.Exists(to)) { Directory.CreateDirectory(to); } Directory.Move(from, to); }
public static void AddExceptions(Exceptions item) { try { item.Track = SubString(item.Track, 2000); item.Source = SubString(item.Source, 100); item.Description = SubString(item.Description, 400); item.Detail = SubString(item.Detail, 1000); item.DateTime = DateTime.Now; IExceptions factory = ExceptionsFactory.GetFactory(); factory.AddExceptions(item); } catch (Exception ex) { TxtLogServices.WriteTxtLogEx("AddExceptionsLogError", ex); } }
public async Task RemoveItemAsync(Guid purchaseId, Guid purchaseItemId) { Purchase purchase = await _purchaseRepository.FindAsync(purchaseId); if (purchase is null) { throw ExceptionsFactory.FactoryNotFoundException <Purchase>(purchaseId); } PurchaseItem purchaseItem = purchase.FindItemById(purchaseItemId); if (purchaseItem is null) { throw ExceptionsFactory.FactoryNotFoundException <PurchaseItem>(purchaseItemId); } await _purchaseService.RemoveItemAsync(purchase, purchaseItem); }
public async Task <ApplicationDataResult <PurchaseDto> > UpdateAsync(Guid purchaseId, AddOrUpdatePurchaseDto data) { ValidationResult validationResult = await _validatorPurchase.ValidateAsync(data); if (validationResult.IsValid is false) { return(FactoryFromValidationResult <PurchaseDto>(validationResult)); } Purchase purchase = await _purchaseRepository.FindAsync(purchaseId); if (purchase is null) { throw ExceptionsFactory.FactoryNotFoundException <Purchase>(purchaseId); } purchase.Update(data.Description, data.Date); _purchaseRepository.Update(purchase); await _purchaseRepository.UnitOfWork.CommitAsync(); return(FactoryResultFromData(_mapper.Map <PurchaseDto>(purchase))); }