public Boolean DeletarPractice(int IdPractice) { try { #region Apagar Anexo Practices var ListAnexo = _repositoryPracticesAnexo.Listar(o => o.IdPractice == IdPractice); if (ListAnexo.Count() > 0) { foreach (var item in ListAnexo) { _repositoryPracticesAnexo.Apagar(item); _repositoryPracticesAnexo.Context.SaveChanges(); } } #endregion #region Apagar Authors Practices var ListAuthorsPractices = _repositoryPracticesAuthors.Listar(o => o.IdPractice == IdPractice); if (ListAuthorsPractices.Count() > 0) { foreach (var item in ListAuthorsPractices) { _repositoryPracticesAuthors.Apagar(item); _repositoryPracticesAuthors.Context.SaveChanges(); } } #endregion #region Apagar Practices var PracticesnEntity = new PracticesEntity { Id = IdPractice }; _repositoryPractices.Apagar(PracticesnEntity); _repositoryPractices.Context.SaveChanges(); #endregion return(true); }catch (Exception e) { Console.WriteLine(e); return(false); } }
public Boolean SalvarPractices(PracticesVM objeto) { try { #region Salvar Practice var practicesEntity = new PracticesEntity { Id = objeto.Id, Name = objeto.Name, Description = objeto.Description, TypesAiMlApplications = objeto.TypesAiMlApplications, OrganizationContext = objeto.OrganizationContext, SeKnowLedge = objeto.SeKnowLedge, ContribuitionTypes = objeto.ContribuitionTypes, Link = objeto.Link, ReferencesDescribing = objeto.ReferencesDescribing, IdUser = objeto.IdUser }; #region Add Or Update if (objeto.Id > 0) { _repositoryPractices.Update(practicesEntity); } else { _repositoryPractices.Salvar(practicesEntity); } #endregion _repositoryPractices.Context.SaveChanges(); objeto.Id = practicesEntity.Id; #endregion #region Salvar Anexos Practices if (objeto.AnexosPractice.Count() > 0) { foreach (var item in objeto.AnexosPractice) { var practicesAnexoEntity = new PracticesAnexoEntity(); practicesAnexoEntity.Id = item.Id; practicesAnexoEntity.Name = item.Name; practicesAnexoEntity.ObjetoAnexo = item.ObjetoAnexo; practicesAnexoEntity.IdPractice = practicesEntity.Id; practicesAnexoEntity.ExtensaoAnexo = item.ExtensaoAnexo; #region Add Or Update if (item.Id > 0) { _repositoryPracticesAnexo.Update(practicesAnexoEntity); } else { _repositoryPracticesAnexo.Salvar(practicesAnexoEntity); } _repositoryPracticesAnexo.Context.SaveChanges(); #endregion practicesAnexoEntity = new PracticesAnexoEntity(); } } #endregion #region Salvar Author Practices if (objeto.AuthorsPractice.Count() > 0) { foreach (var item in objeto.AuthorsPractice) { var practicesAuthorsEntity = new PracticesAuthorsEntity(); practicesAuthorsEntity.Id = item.Id; practicesAuthorsEntity.IdPractice = practicesEntity.Id; practicesAuthorsEntity.IdUser = item.IdUser; #region Add Or Update if (item.Id > 0) { _repositoryPracticesAuthors.Update(practicesAuthorsEntity); } else { _repositoryPracticesAuthors.Salvar(practicesAuthorsEntity); } _repositoryPracticesAnexo.Context.SaveChanges(); #endregion practicesAuthorsEntity = new PracticesAuthorsEntity(); } } #endregion return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }