public virtual async Task <TDto> CreateAsync(TDto dto, Action <string, string> AddErrorMessage) { if (!await ValidateCrUpDataAsync(dto, AddErrorMessage)) { return(null); } TEntity entity = _mappingService.DtoToEntity(dto); TEntity createdEntity = await _repository.CreateAsync(entity); if (createdEntity != null) { await _context.SaveChangesAsync(); } createdEntity = await _repository.GetCompleteAsync(createdEntity.ID); return(_mappingService.EntityToDto(createdEntity)); }
public async Task CreateAsync(Product product) { bool isInvalid = false; PropertyInfo[] properties = typeof(Product).GetProperties(); for (int i = 1; i < properties.Length; i++) { if (properties[i].Name != "Quantity") { if (properties[i].GetValue(product) == null || string.IsNullOrWhiteSpace(properties[i].GetValue(product).ToString()) || properties[i].GetValue(product).ToString() == "0" || properties[i].GetValue(product).ToString().StartsWith("-")) { isInvalid = true; } } } if (!isInvalid) { await productRepository.CreateAsync(product); } }