private async Task<ImportValidationResultInfo> MapAndValidate(CommodityTypeDTO dto, int index) { return await Task.Run(() => { var entity = _mappingService.Map(dto); var exist = _ctx.tblCommodityType.FirstOrDefault( p => p.Name.ToLower() == dto.Name.ToLower() || p.Code != null && p.Code.Equals(dto.Code, StringComparison.CurrentCultureIgnoreCase)); 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; }); }
private CommodityTypeDTO Map(tblCommodityType tbl) { var dto = new CommodityTypeDTO { MasterId = tbl.Id, DateCreated = tbl.IM_DateCreated, DateLastUpdated = tbl.IM_DateLastUpdated, StatusId = tbl.IM_Status, Name = tbl.Name, Code = tbl.Code, Description = tbl.Description }; return dto; }
public CommodityType Map(CommodityTypeDTO dto) { if (dto == null) return null; var commodityType = Mapper.Map<CommodityTypeDTO, CommodityType>(dto); return commodityType; }