Created
December 30, 2018 17:04
-
-
Save azaharafernandezguizan/7d764d7c5eb02e561d3de68bec0ad6f6 to your computer and use it in GitHub Desktop.
Repository implementation on NetCore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using MyDBContext.Models; | |
using Microsoft.EntityFrameworkCore; | |
namespace MicrobiologiaBusinessLogic | |
{ | |
public class RecursosRepository : IRecursosRepository, IDisposable | |
{ | |
private myContext context; | |
public RecursosRepository(myContext context) | |
{ | |
this.context = context; | |
} | |
public void DeleteRecurso(int recursoID) | |
{ | |
Recursos recurso = context.Recursos.Find(recursoID); | |
context.Recursos.Remove(recurso); | |
} | |
public List<Recursos> GetAllRecursos() | |
{ | |
return context.Recursos.ToList(); | |
} | |
public Recursos GetRecursoById(int recursoID) | |
{ | |
return context.Recursos.Find(recursoID); | |
} | |
public void InsertRecurso(Recursos recurso) | |
{ | |
context.Recursos.Add(recurso); | |
} | |
public void UpdateRecurso(Recursos recurso) | |
{ | |
context.Entry(recurso).State = EntityState.Modified; | |
} | |
#region IDisposable Support | |
private bool disposedValue = false; | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (!disposedValue) | |
{ | |
if (disposing) | |
{ | |
context.Dispose(); | |
} | |
disposedValue = true; | |
} | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment