コード例 #1
0
        private async Task<ImportValidationResultInfo> MapAndValidate(RouteDTO dto, int index)
        {
            return await Task.Run(() =>
            {
                if (dto == null) return null;
                var entity = _mappingService.Map(dto);
                var exist = _ctx.tblRoutes.FirstOrDefault(p => p.Name.ToLower() == dto.Name.ToLower()||p.Code !=null &&p.Code.ToLower()==dto.Code.ToLower());

                entity.Id = exist == null ? Guid.NewGuid() : exist.RouteID;

                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;

            });


        }
コード例 #2
0
 public Route Map(RouteDTO dto)
 {
     if (dto == null) return null;
     var route = Mapper.Map<RouteDTO, Route>(dto);
     route.Region = _regionRepository.GetById(dto.RegionId);
     return route;
 }