public void Delete(T entity) { SocarEntities context = CreateContext(); context.Entry(entity).State = EntityState.Deleted; context.SaveChanges(); }
public List <Event> Search(int?codeId, DateTime?period) { SocarEntities context = CreateContext(); var query = from x in context.Events select new { Event = x, EventName = x.Code.Item }; if (codeId.HasValue) { query = query.Where(x => x.Event.EventTypeCode == codeId); } if (period.HasValue) { query = query.Where(x => x.Event.Period > period.Value); } var items = query.ToList(); foreach (var x in items) { x.Event.EventName = x.EventName; } return(items.ConvertAll(x => x.Event)); }
public List <Insurance> Search(int?companyCode, int?goodsCode) { SocarEntities context = CreateContext(); var query = from x in context.Insurances select new { Insurance = x, CompanyName = x.Code.Item, GoodsName = x.Code1.Item }; if (companyCode.HasValue) { query = query.Where(x => x.Insurance.CompanyCode == companyCode); } if (goodsCode.HasValue) { query = query.Where(x => x.Insurance.GoodsCode == goodsCode); } var items = query.ToList(); foreach (var x in items) { x.Insurance.CompanyName = x.CompanyName; x.Insurance.GoodsName = x.GoodsName; } return(items.ConvertAll(x => x.Insurance)); }
public List <Location> Search(int?codeId, int?locationId) { SocarEntities context = CreateContext(); var query = from x in context.Locations select new { Location = x, LocationName = x.Code.Item, LocationFullName = x.Code.Item + " " + x.Address, CarName = x.Cars.Select(y => y.CarType.Name).FirstOrDefault(), CarNumber = x.Cars.Select(y => y.Number).FirstOrDefault() }; if (codeId.HasValue) { query = query.Where(x => x.Location.LocationCode == codeId); } if (locationId.HasValue) { query = query.Where(x => x.Location.LocationId == locationId); } var items = query.ToList(); foreach (var x in items) { x.Location.LocationName = x.LocationName; x.Location.LocationFullName = x.LocationFullName; x.Location.CarName = x.CarName; x.Location.CarNumber = x.CarNumber; } return(items.ConvertAll(x => x.Location)); }
public void Insert(T entity) { SocarEntities context = CreateContext(); context.Entry(entity).State = EntityState.Added; context.SaveChanges(); }
public virtual void Update(T entity) { SocarEntities context = CreateContext(); context.Entry(entity).State = EntityState.Modified; context.SaveChanges(); }
public SocarEntities CreateContext() { SocarEntities context = new SocarEntities(); context.Configuration.ProxyCreationEnabled = false; context.Database.Log = x => Console.WriteLine(x); return(context); }
public int?GetFirstId() { SocarEntities context = CreateContext(); var query = from x in context.Locations orderby x.LocationId select x.LocationId; return(query.FirstOrDefault()); }
public List <Event> getByCodeId(int eventTypeId) { SocarEntities context = CreateContext(); var query = from x in context.Events where x.EventTypeCode == eventTypeId select x; return(query.ToList()); }
public List <Location> GetByCodeCategory(int?codeId) { SocarEntities context = CreateContext(); var query = from x in context.Locations select x; if (codeId.HasValue) { query = query.Where(x => x.LocationCode == codeId); } return(query.ToList()); }
public List <Rent> Search(int?customerId, int?locationId, int?carId, DateTime?rentDay, DateTime?returnDay) { SocarEntities context = CreateContext(); var query = from x in context.Rents select new { Rent = x, CustomerName = x.Customer.Name, CarName = x.Car.CarType.Name, EventCount = x.Events.Count }; if (customerId.HasValue) { query = query.Where(x => x.Rent.CustomerId == customerId); } if (locationId.HasValue) { query = query.Where(x => x.Rent.LocationId == locationId); } if (carId.HasValue) { query = query.Where(x => x.Rent.CarId == carId); } if (rentDay.HasValue) { var boundaryValue = rentDay.Value.AddDays(1); query = query.Where(x => x.Rent.BookAt >= rentDay.Value && x.Rent.BookAt <= boundaryValue); } if (returnDay.HasValue) { var boundaryValue = returnDay.Value.AddDays(1); query = query.Where(x => x.Rent.ReturnAt >= returnDay.Value && x.Rent.ReturnAt <= boundaryValue); } var items = query.ToList(); foreach (var x in items) { x.Rent.CustomerName = x.CustomerName; x.Rent.CarName = x.CarName; x.Rent.EventCount = x.EventCount; } return(query.ToList().ConvertAll(x => x.Rent)); }
public List <Rent> GetAllWithProperties() { SocarEntities context = CreateContext(); var query = from x in context.Rents select new { Rent = x, CustomerName = x.Customer.Name, CarNumber = x.Car.Number, Address = x.Car.Location.Address }; var items = query.ToList(); foreach (var x in items) { x.Rent.CustomerName = x.CustomerName; x.Rent.CarNumber = x.CarNumber; x.Rent.Address = x.Address; } return(items.ConvertAll(x => x.Rent)); }
public List <Car> GetAllWithProperties() { SocarEntities context = CreateContext(); var query = from x in context.Cars select new { Car = x, CarName = x.CarType.Name, Address = x.Location.Address, DefectCount = x.Defects.Count }; var items = query.ToList(); foreach (var x in items) { x.Car.CarName = x.CarName; x.Car.Address = x.Address; x.Car.DefectCount = x.DefectCount; } return(items.ConvertAll(x => x.Car)); }
public List <Customer> Search(int?customerId, int?age, string cellNumber, int?lisence) { SocarEntities context = CreateContext(); var query = from x in context.Customers select new { Customer = x, Lisence = x.Code.Item, RentCount = x.Rents.Count }; if (customerId.HasValue) { query = query.Where(x => x.Customer.CustomerId == customerId); } if (age.HasValue) { query = query.Where(x => x.Customer.Age == age); } if (string.IsNullOrEmpty(cellNumber) == false) { query = query.Where(x => x.Customer.CellNumber.Contains(cellNumber)); } if (lisence.HasValue) { query = query.Where(x => x.Customer.LisenceCode == lisence); } var items = query.ToList(); foreach (var x in items) { x.Customer.Lisence = x.Lisence; x.Customer.RentCount = x.RentCount; } return(items.ConvertAll(x => x.Customer)); }
public List <Car> Search(int?carId, int?carTypeId, int?location, bool?isRent) { SocarEntities context = CreateContext(); var query = from x in context.Cars select new { Car = x, CarName = x.CarType.Name, Address = x.Location.Address, DefectCount = x.Defects.Count }; if (carId.HasValue) { query = query.Where(x => x.Car.CarId == carId); } if (carTypeId.HasValue) { query = query.Where(x => x.Car.CarTypeId == carTypeId); } if (location.HasValue) { query = query.Where(x => x.Car.LocationId == location); } if (isRent.HasValue) { query = query.Where(x => x.Car.IsRent == isRent); } var items = query.ToList(); foreach (var x in items) { x.Car.CarName = x.CarName; x.Car.Address = x.Address; x.Car.DefectCount = x.DefectCount; } return(items.ConvertAll(x => x.Car)); }
public Location Get(int locationId) { SocarEntities context = CreateContext(); return(context.Locations.FirstOrDefault(x => x.LocationId == locationId)); }
public Defect Get(int defectId) { SocarEntities context = CreateContext(); return(context.Defects.FirstOrDefault(x => x.DefectId == defectId)); }
public Rent Get(int rentId) { SocarEntities context = CreateContext(); return(context.Rents.FirstOrDefault(x => x.RentId == rentId)); }
public Customer Get(int customerId) { SocarEntities context = CreateContext(); return(context.Customers.FirstOrDefault(x => x.CustomerId == customerId)); }
public Car Get(int carId) { SocarEntities context = CreateContext(); return(context.Cars.FirstOrDefault(x => x.CarId == carId)); }
public Event Get(int eventId) { SocarEntities context = CreateContext(); return(context.Events.FirstOrDefault(x => x.EventId == eventId)); }
public Insurance Get(int insuranceId) { SocarEntities context = CreateContext(); return(context.Insurances.FirstOrDefault(x => x.InsuranceId == insuranceId)); }
public Code Get(int codeId) { SocarEntities context = CreateContext(); return(context.Codes.FirstOrDefault(x => x.CodeId == codeId)); }
public List <T> GetAll() { SocarEntities context = CreateContext(); return(context.Set <T>().ToList()); }
public int GetCount() { SocarEntities context = CreateContext(); return(context.Set <T>().Count()); }