public int Create(Users entity)
{
using (var context = new K305DataEntities())
{
var newEntity = Mapper.Map<User>(entity);
context.Users.Add(newEntity);
context.SaveChanges();
return newEntity.Id;
}
}
public int Update(Users entity)
{
using (var context = new K305DataEntities())
{
var dbEntity = context.Users.FirstOrDefault(dc => dc.Id == entity.Id);
if (dbEntity == null) throw new ApplicationException("Entity not found.");
dbEntity.Name = entity.Name;
context.SaveChanges();
return dbEntity.Id;
}
}
public List<Users> GetAll()
{
using (var context = new K305DataEntities())
{
return context.Users.Select(
rhf =>
new Users
{
Id = rhf.Id,
Name = rhf.Name,
EmailId = rhf.EmailId,
BirthDate = rhf.BirthDate,
IsActive = rhf.IsActive
}).OrderBy(o => o.Name).ToList();
}
}
public Users GetById(int id)
{
using (var context = new K305DataEntities())
{
return context.Users.Where(u => u.Id == id).Select(
rhf =>
new Users
{
Id = rhf.Id,
Name = rhf.Name,
EmailId = rhf.EmailId,
BirthDate = rhf.BirthDate,
IsActive = rhf.IsActive
}).FirstOrDefault();
}
}
public void Delete(Users entity)
{
using (var context = new K305DataEntities())
{
var old = context.Users.FirstOrDefault(t => t.Id == entity.Id);
context.Users.Remove(old);
context.SaveChanges();
}
}
{
using (var context = new K305DataEntities())
{
var newEntity = Mapper.Map<User>(entity);
context.Users.Add(newEntity);
context.SaveChanges();
return newEntity.Id;
}
}
public int Update(Users entity)
{
using (var context = new K305DataEntities())
{
var dbEntity = context.Users.FirstOrDefault(dc => dc.Id == entity.Id);
if (dbEntity == null) throw new ApplicationException("Entity not found.");
dbEntity.Name = entity.Name;
context.SaveChanges();
return dbEntity.Id;
}
}
public List<Users> GetAll()
{
using (var context = new K305DataEntities())
{
return context.Users.Select(
rhf =>
new Users
{
Id = rhf.Id,
Name = rhf.Name,
EmailId = rhf.EmailId,
BirthDate = rhf.BirthDate,
IsActive = rhf.IsActive
}).OrderBy(o => o.Name).ToList();
}
}
public Users GetById(int id)
{
using (var context = new K305DataEntities())
{
return context.Users.Where(u => u.Id == id).Select(
rhf =>
new Users
{
Id = rhf.Id,
Name = rhf.Name,
EmailId = rhf.EmailId,
BirthDate = rhf.BirthDate,
IsActive = rhf.IsActive
}).FirstOrDefault();
}
}
public void Delete(Users entity)
{
using (var context = new K305DataEntities())
{
var old = context.Users.FirstOrDefault(t => t.Id == entity.Id);
context.Users.Remove(old);
context.SaveChanges();
}
}
Comments
Post a Comment