Ejemplo n.º 1
0
        public void Delete(T entity)
        {
            SocarEntities context = CreateContext();

            context.Entry(entity).State = EntityState.Deleted;
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        public void Insert(T entity)
        {
            SocarEntities context = CreateContext();

            context.Entry(entity).State = EntityState.Added;
            context.SaveChanges();
        }
Ejemplo n.º 6
0
        public virtual void Update(T entity)
        {
            SocarEntities context = CreateContext();

            context.Entry(entity).State = EntityState.Modified;

            context.SaveChanges();
        }
Ejemplo n.º 7
0
        public SocarEntities CreateContext()
        {
            SocarEntities context = new SocarEntities();

            context.Configuration.ProxyCreationEnabled = false;
            context.Database.Log = x => Console.WriteLine(x);

            return(context);
        }
Ejemplo n.º 8
0
        public int?GetFirstId()
        {
            SocarEntities context = CreateContext();

            var query = from x in context.Locations
                        orderby x.LocationId
                        select x.LocationId;

            return(query.FirstOrDefault());
        }
Ejemplo n.º 9
0
        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());
        }
Ejemplo n.º 10
0
        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());
        }
Ejemplo n.º 11
0
        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));
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
        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));
        }
Ejemplo n.º 16
0
        public Location Get(int locationId)
        {
            SocarEntities context = CreateContext();

            return(context.Locations.FirstOrDefault(x => x.LocationId == locationId));
        }
Ejemplo n.º 17
0
        public Defect Get(int defectId)
        {
            SocarEntities context = CreateContext();

            return(context.Defects.FirstOrDefault(x => x.DefectId == defectId));
        }
Ejemplo n.º 18
0
        public Rent Get(int rentId)
        {
            SocarEntities context = CreateContext();

            return(context.Rents.FirstOrDefault(x => x.RentId == rentId));
        }
Ejemplo n.º 19
0
        public Customer Get(int customerId)
        {
            SocarEntities context = CreateContext();

            return(context.Customers.FirstOrDefault(x => x.CustomerId == customerId));
        }
Ejemplo n.º 20
0
        public Car Get(int carId)
        {
            SocarEntities context = CreateContext();

            return(context.Cars.FirstOrDefault(x => x.CarId == carId));
        }
Ejemplo n.º 21
0
        public Event Get(int eventId)
        {
            SocarEntities context = CreateContext();

            return(context.Events.FirstOrDefault(x => x.EventId == eventId));
        }
Ejemplo n.º 22
0
        public Insurance Get(int insuranceId)
        {
            SocarEntities context = CreateContext();

            return(context.Insurances.FirstOrDefault(x => x.InsuranceId == insuranceId));
        }
Ejemplo n.º 23
0
        public Code Get(int codeId)
        {
            SocarEntities context = CreateContext();

            return(context.Codes.FirstOrDefault(x => x.CodeId == codeId));
        }
Ejemplo n.º 24
0
        public List <T> GetAll()
        {
            SocarEntities context = CreateContext();

            return(context.Set <T>().ToList());
        }
Ejemplo n.º 25
0
        public int GetCount()
        {
            SocarEntities context = CreateContext();

            return(context.Set <T>().Count());
        }