public void Delete(Guid IdCategoria)
 {
     repository.Delete(IdCategoria);
 }
Пример #2
0
        public void Update(Guid Idexame, ExameDTO exameNew)
        {
            var _exameNew = mapper.Map <exame>(exameNew);

            repository.Update(Idexame, _exameNew);

            var idcategoriasExame = exameNew.categoriaexame.Where(a => a.idcategoriaexame != null)
                                    .Select(a => (Guid)a.idcategoriaexame)
                                    .ToArray();

            var idcategoriasExameDell = categoriaExameRepository.List()
                                        .Where(a => a.idexame == Idexame && !idcategoriasExame.Contains(a.idcategoriaexame))
                                        .Select(a => a.idcategoriaexame)
                                        .ToArray();

            foreach (var iddell in idcategoriasExameDell)
            {
                categoriaExameRepository.Delete(iddell);
            }

            foreach (var categoriaExame in exameNew.categoriaexame)
            {
                var _categoriaExame = mapper.Map <categoriaexame>(categoriaExame);

                if (categoriaExame.idcategoriaexame == null)
                {
                    _categoriaExame.idcategoriaexame = Guid.NewGuid();
                    _categoriaExame.idexame          = _exameNew.idexame;

                    categoriaExameRepository.Insert(_categoriaExame);
                }
                else
                {
                    categoriaExameRepository.Update(_categoriaExame.idcategoriaexame, _categoriaExame);
                }
            }

            var idexameRespsDiag = exameNew.examemedicorespdiagnostico.Where(a => a.idexmeddiag != null)
                                   .Select(a => (Guid)a.idexmeddiag)
                                   .ToArray();

            var idexameRespsDiagDell = exameMedicorespDiagnosticoRepository.List()
                                       .Where(a => a.idexame == Idexame && !idexameRespsDiag.Contains(a.idexmeddiag))
                                       .Select(a => a.idexmeddiag)
                                       .ToArray();

            foreach (var iddell in idexameRespsDiagDell)
            {
                exameMedicorespDiagnosticoRepository.Delete(iddell);
            }

            foreach (var exameMedRespDiag in exameNew.examemedicorespdiagnostico)
            {
                var _exameMedRespDiag = mapper.Map <examemedicorespdiagnostico>(exameMedRespDiag);

                if (exameMedRespDiag.idexmeddiag == null)
                {
                    _exameMedRespDiag.idexmeddiag = Guid.NewGuid();
                    _exameMedRespDiag.idexame     = _exameNew.idexame;

                    exameMedicorespDiagnosticoRepository.Insert(_exameMedRespDiag);
                }
                else
                {
                    exameMedicorespDiagnosticoRepository.Update(_exameMedRespDiag.idexmeddiag, _exameMedRespDiag);
                }
            }

            var idimagens = exameNew.imagem.Where(a => a.idexame != null)
                            .Select(a => (Guid)a.idimagem)
                            .ToArray();

            var idimagensDell = imagemRepository.List()
                                .Where(a => a.idexame == Idexame && !idimagens.Contains(a.idimagem))
                                .Select(a => a.idimagem)
                                .ToArray();

            foreach (var iddell in idimagensDell)
            {
                imagemRepository.Delete(iddell);
            }

            foreach (var imagem in exameNew.imagem)
            {
                var _imagem = mapper.Map <imagem>(imagem);

                _imagem.idexame = _exameNew.idexame;

                imagemRepository.Update(imagem.idimagem, _imagem);
            }
        }