public
bool
AddEntity(Customer entity)
{
MyHotelModelContainer hotelDB =
new
MyHotelModelContainer();
if
(entity.Id == Guid.Empty)
{
entity.Id = Guid.NewGuid();
}
hotelDB.Customer.AddObject(entity);
int
count = hotelDB.SaveChanges();
if
(count > 0)
{
return
true
;
}
return
false
;
}
public
bool
UpdateEntity(Customer entity)
{
bool
result =
false
;
MyHotelModelContainer hotelDB =
new
MyHotelModelContainer();
hotelDB.Customer.Attach(entity);
hotelDB.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Modified);
int
count = hotelDB.SaveChanges();
if
(count > 0)
{
result =
true
;
}
return
result;
}
public
bool
DeleteEntity(Guid Id)
{
bool
result =
false
;
MyHotelModelContainer hoteDB =
new
MyHotelModelContainer();
var
tempDelete = hoteDB.Customer.Where<Customer>(c => c.Id == Id).FirstOrDefault<Customer>();<span style=
"white-space:pre"
> </span>
if
(tempDelete !=
null
)
{
hoteDB.Customer.DeleteObject(tempDelete);
var
count = hoteDB.SaveChanges();
if
(count > 0)
result =
true
;
}
return
result;
}
public
IQueryable<Customer> GetByWhere(Func<Customer,
bool
> whereLambda)
{<span style=
"white-space:pre"
> </span>
MyHotelModelContainer hoteDB =
new
MyHotelModelContainer();
var
temp = hoteDB.Customer.Where<Customer>(whereLambda).AsQueryable<Customer>();
return
temp;
}
public
IQueryable<Customer> GetPageEntity(Func<Customer,
bool
> whereLambda,
int
? pageSize,
int
? pageIndex)
{
MyHotelModelContainer hotelDB =
new
MyHotelModelContainer();
var
temp = hotelDB.Customer
.Where<Customer>(whereLambda)
.OrderBy(c => c.FirstName)
.Skip<Customer>(pageSize.Value * (pageIndex.Value - 1))
.Take<Customer>(pageSize.Value)
.AsQueryable<Customer>();
return
temp;
}
public
long
GetCount(Func<Customer,
bool
> whereLambda)
{
MyHotelModelContainer hotelDB =
new
MyHotelModelContainer();
return
hotelDB.Customer.Where<Customer>(whereLambda).Count();
}