private async Task<ImportValidationResultInfo> MapAndValidate(DiscountGroupDTO dto, int index) { return await Task.Run(() => { var entity = _mappingService.Map(dto); var exist = _ctx.tblDiscountGroup.FirstOrDefault(p => p.Code.ToLower() == dto.Code.ToLower() || p.Name.ToLower() == dto.Name.ToLower()); entity.Id = exist == null ? Guid.NewGuid() : exist.id; var res = _repository.Validate(entity); var vResult = new ImportValidationResultInfo() { Results = res.Results, Description = string.Format("Row-{0} name or code=>{1}", index, entity.Name ?? entity.Code), Entity = entity }; return vResult; }); }
public DiscountGroup Map(DiscountGroupDTO dto) { if (dto == null) return null; var discountGroup = Mapper.Map<DiscountGroupDTO, DiscountGroup>(dto); return discountGroup; }