2
I have the following classes:
class Disciplina
:
public class Disciplina
{
public int Id { get; set; }
public string Nome { get; set; }
}
interface IGenericaDAO
:
public interface IGenericaDAO<T>
{
bool Add(T e);
bool Update(T e);
bool Delete(T e);
List<T> GetAll();
T Get(int id);
}
interface IDisciplinaDAO
:
public interface IDisciplinaDAO : IGenericaDAO<Disciplina>
{
}
class GenericaDAO
:
public class GenericaDAO<T> : IGenericaDAO<T> where T : class
{
internal ApplicationDbContext Context { get; set; }
protected DbSet<T> DbSet { get; set; }
public GenericaDAO()
{
Context = new ApplicationDbContext();
DbSet = Context.Set<T>();
}
public bool Add(T e)
{
try
{
Context.Entry(e).State = EntityState.Added;
Context.SaveChanges();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
public bool Update(T e)
{
try
{
Context.Entry(e).State = EntityState.Modified;
Context.SaveChanges();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
public bool Delete(T e)
{
try
{
Context.Entry(e).State = EntityState.Deleted;
Context.SaveChanges();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
public List<T> GetAll()
{
return DbSet.ToList();
}
public T Get(int id)
{
return DbSet.Find(id);
}
}
class DisciplinaDAO
:
public class DisciplinaDAO : GenericaDAO<Disciplina>, IDisciplinaDAO
{
}
interface IGenericaBLO
:
public interface IGenericaBLO<T>
{
bool Add(T e);
bool Update(T e);
bool Delete(T e);
List<T> GetAll();
T Get(int id);
}
public interface IGenericaBLO<T>
{
bool Add(T e);
bool Update(T e);
bool Delete(T e);
List<T> GetAll();
T Get(int id);
}
interface IDisciplinaBLO
:
public interface IDisciplinaBLO : IGenericaBLO<Disciplina>
{
}
class GenericaBLO
:
public class GenericaBLO<T> : IGenericaBLO<T> where T : class
{
private IGenericaDAO<T> dao;
public GenericaBLO(IGenericaDAO<T> _dao)
{
dao = _dao;
}
public bool Add(T e)
{
bool resultado = dao.Add(e);
return resultado;
}
public bool Update(T e)
{
bool resultado = dao.Update(e);
return resultado;
}
public bool Delete(T e)
{
bool resultado = dao.Delete(e);
return resultado;
}
public List<T> GetAll()
{
return dao.GetAll();
}
public T Get(int id)
{
return dao.Get(id);
}
}
class DisciplinaBLO
:
public class DisciplinaBLO : GenericaBLO<Disciplina>, IDisciplinaBLO
{}
I am getting the following build error in the class DisciplinaBLO
:
Error 1 'Core.BLL.Base.Genericablo' does not contain a constructor that takes 0 Arguments Disciplinablo.Cs 12 18 Core
There are many things that seem to be repeated there, edit the question and remove if it really is.
– user28595
Hello, it doesn’t seem to me to have something repeated no. I put all the classes and interfaces to help find the error. I already found, missed declaring the constructor of the Genericablo class, because once you create a constructor with parameters, the default constructor (no parameters) is not created automatically.
– Leandro Duarte
There’s a lot of bad stuff in this code. Where are you making that mistake? In a call or in a class you’re inheriting
GenericaBLO
, right? Show us this.– Maniero
I’m getting the following build error in the Disciplinablo class. Helps me, which is bad in code?
– Leandro Duarte
@Leandroduarte And what’s in
DisciplinaBLO
? Nothing? Then why is there such a class?– Maniero
Because it will have an implementation later. I am specializing for reuse.
– Leandro Duarte