private async Task<ImportValidationResultInfo> MapAndValidate(VATClassDTO dto, int index) { return await Task.Run(() => { if (dto == null) return null; var entity = _mappingService.Map(dto); var exist = _ctx.tblVATClass.FirstOrDefault(p =>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 = entity }; return vResult; }); }
private VATClassDTO Map(tblVATClass tbl) { var dto = new VATClassDTO { MasterId = tbl.id, DateCreated = tbl.IM_DateCreated, DateLastUpdated = tbl.IM_DateLastUpdated, StatusId = tbl.IM_Status, Name = tbl.Name, VatClass = tbl.Class, VatClassItems = new List<VatClassItemDTO>() }; foreach (var item in tbl.tblVATClassItem.Where(n => n.IM_Status== (int)EntityStatus.Active)) { var dtoitem = new VatClassItemDTO { MasterId = item.id, DateCreated = item.IM_DateCreated, DateLastUpdated = item.IM_DateLastUpdated, StatusId = item.IM_Status, Rate = item.Rate, EffectiveDate = item.EffectiveDate, VatClassMasterId = item.VATClassID, }; dto.VatClassItems.Add(dtoitem); } return dto; }
public VATClassDTO Map(VATClass vatClass) { if (vatClass == null) return null; var item = new VATClassDTO() { DateCreated = vatClass._DateCreated, DateLastUpdated = vatClass._DateLastUpdated, StatusId =(int) vatClass._Status, MasterId = vatClass.Id, Name = vatClass.Name, VatClass = vatClass.VatClass, VatClassItems = vatClass.VATClassItems .Select(n => new VatClassItemDTO { DateCreated = n._DateCreated, DateLastUpdated = n._DateLastUpdated, EffectiveDate = n.EffectiveDate, StatusId = (int)n._Status, MasterId = n.Id, Rate = n.Rate }).ToList() }; return item; }
public VATClass Map(VATClassDTO dto) { if (dto == null) return null; var vatClass = Mapper.Map<VATClassDTO, VATClass>(dto); vatClass.VATClassItems = dto.VatClassItems.Select(n => Map(n, n.MasterId)).ToList(); return vatClass; }