Пример #1
0
        public void CreateSubZone(Guid id, ZoneDTO zoneDTO)
        {
            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                var query = from z in context.Zones
                            where z.Id == id
                            select z;
                Zone mainZone = query.ToList().FirstOrDefault();

                Zone subzone = this.mapper.ToEntity(zoneDTO);
                if (zoneDTO.FlowStep != null)
                {
                    var querySZ = from f in context.FlowSteps
                                  where f.Name == zoneDTO.FlowStep.Name
                                  select f;
                    FlowStep flowStep = querySZ.ToList().FirstOrDefault();
                    subzone.FlowStep = flowStep;
                    context.FlowSteps.Attach(flowStep);
                }

                context.Zones.Add(subzone);
                if (mainZone != null)
                {
                    mainZone.SubZones.Add(subzone);
                    context.SaveChanges();
                }
            }
        }
Пример #2
0
        public void CreateFlow(Dictionary <int, FlowStepDTO> steps)
        {
            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                foreach (FlowItem flowItem in context.FlowItems)
                {
                    context.FlowItems.Remove(flowItem);
                }

                foreach (int key in steps.Keys)
                {
                    FlowItem flowItem = new FlowItem();
                    flowItem.StepNumber = key;
                    flowItem.Id         = Guid.NewGuid();
                    string stepName = steps[key].Name;
                    var    query    = from f in context.FlowSteps
                                      where f.Name == stepName
                                      select f;
                    FlowStep flowStep = query.ToList().FirstOrDefault();

                    flowItem.FlowStep = flowStep;

                    context.FlowItems.Add(flowItem);
                }
                context.SaveChanges();
            }
        }
Пример #3
0
        public ZoneDTO FindZoneById(Guid id)
        {
            Zone    zone    = null;
            ZoneDTO zoneDTO = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                zone = context.Zones
                       .Include("Vehicles")
                       .Include("SubZones")
                       .Where(z => z.Id == id)
                       .ToList().FirstOrDefault();

                if (zone != null)
                {
                    if (zone.SubZones.Count == 0)
                    {
                        zone.SubZones = null;
                    }
                    if (zone.Vehicles.Count == 0)
                    {
                        zone.Vehicles = null;
                    }
                    zoneDTO = this.mapper.ToDTO(zone);
                }
            }
            return(zoneDTO);
        }
Пример #4
0
        public InspectionDTO FindInspectionById(Guid id)
        {
            Inspection    inspection    = null;
            InspectionDTO inspectionDTO = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                inspection = context.Inspections
                             .Include("Damages")
                             .Include("IdLocation")
                             .Include("IdUser")
                             .Include("IdVehicle")
                             .Where(i => i.Id == id)
                             .ToList().FirstOrDefault();
                if (inspection != null)
                {
                    List <Damage> damages = new List <Damage>();
                    foreach (Damage damage in inspection.Damages)
                    {
                        Damage dam = context.Damages
                                     .Include("Images")
                                     .Where(d => d.Id == damage.Id)
                                     .ToList().FirstOrDefault();
                        damages.Add(dam);
                    }
                    inspection.Damages = damages;
                }
            }
            if (inspection != null)
            {
                inspectionDTO = this.inspectionMapper.ToDTO(inspection);
            }
            return(inspectionDTO);
        }
Пример #5
0
        public void Update(ZoneDTO zoneDTO)
        {
            Zone zone = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                var query = from z in context.Zones
                            where z.Id == zoneDTO.Id
                            select z;
                zone = query.ToList().FirstOrDefault();

                if (zone != null)
                {
                    zone.MaxCapacity = zoneDTO.MaxCapacity;
                    zone.Name        = zoneDTO.Name;

                    context.Zones.Attach(zone);
                    var entry = context.Entry(zone);
                    entry.Property(e => e.MaxCapacity).IsModified = true;
                    entry.Property(e => e.Name).IsModified        = true;

                    context.SaveChanges();
                }
            }
        }
Пример #6
0
        private Vehicle GetVehicle(VehicleTrackingDbContext context, string vin)
        {
            Vehicle vehicle = context.Vehicles
                              .Where(v => v.Vin == vin)
                              .ToList().FirstOrDefault();

            return(vehicle);
        }
Пример #7
0
        private User GetUser(VehicleTrackingDbContext context, string userName)
        {
            User user = context.Users
                        .Include("IdRole")
                        .Where(u => u.UserName == userName)
                        .ToList().FirstOrDefault();

            return(user);
        }
Пример #8
0
        private Batch GetBatchOfVehicle(VehicleTrackingDbContext context, Vehicle vehicle)
        {
            Batch batch = context.Batches
                          .Include("Vehicles")
                          .Where(b => b.Vehicles.Select(v => v.Id).Contains(vehicle.Id))
                          .ToList().FirstOrDefault();

            return(batch);
        }
Пример #9
0
        private Inspection GetInspectionOfVehicle(VehicleTrackingDbContext context, Vehicle vehicle)
        {
            Inspection inspection = context.Inspections
                                    .Include("IdVehicle")
                                    .Where(i => i.IdVehicle.Vin == vehicle.Vin)
                                    .ToList().FirstOrDefault();

            return(inspection);
        }
Пример #10
0
 public Guid AddImage(Base64Image image)
 {
     using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
     {
         context.Images.Add(image);
         context.SaveChanges();
     }
     return(image.Id);
 }
Пример #11
0
        public bool ExistVehicleInspection(string vin)
        {
            bool exist = true;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                exist = context.Inspections.Any(i => i.IdVehicle.Vin == vin);
            }
            return(exist);
        }
Пример #12
0
        public void AddUser(UserDTO userDTO)
        {
            User user = this.userMapper.ToEntity(userDTO);

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                context.Roles.Attach(user.IdRole);
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
Пример #13
0
        public Base64Image FindImageByBase64Encode(string code)
        {
            Base64Image image = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                image = context.Images
                        .Where(i => i.Base64EncodedImage == code)
                        .ToList().FirstOrDefault();
            }
            return(image);
        }
Пример #14
0
        public void CreateStep(FlowStepDTO step)
        {
            FlowStep flowStep = new FlowStep();

            flowStep.Name = step.Name;
            flowStep.Id   = Guid.NewGuid();

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                context.FlowSteps.Add(flowStep);
                context.SaveChanges();
            }
        }
Пример #15
0
 public bool IsAssigned(string vin)
 {
     using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
     {
         VehicleDTO vehicle    = FindVehicleByVin(vin);
         bool       isAssigned = false;
         if (context.Batches.Count() > 0)
         {
             isAssigned = context.Batches.Any(b => b.Vehicles.Any(v => v.Vin == vehicle.Vin));
         }
         return(isAssigned);
     }
 }
Пример #16
0
        private List <Vehicle> GetVehicles(VehicleTrackingDbContext context, List <Vehicle> vehicles)
        {
            List <Vehicle> resultVehicles = new List <Vehicle>();

            foreach (Vehicle vehicle in vehicles)
            {
                Vehicle ve = context.Vehicles
                             .Where(v => v.Vin == vehicle.Vin)
                             .ToList().FirstOrDefault();
                resultVehicles.Add(ve);
            }
            return(resultVehicles);
        }
Пример #17
0
        public List <VehicleDTO> GetAllVehicles()
        {
            List <VehicleDTO> vehiclesDTO = new List <VehicleDTO>();

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                foreach (Vehicle vehicle in context.Vehicles)
                {
                    VehicleDTO dto = this.mapper.ToDTO(vehicle);
                    vehiclesDTO.Add(dto);
                }
            }
            return(vehiclesDTO);
        }
Пример #18
0
        public void AddVehicle(VehicleDTO vehicleDTO)
        {
            Vehicle vehicle = mapper.ToEntity(vehicleDTO);

            vehicle.Id = Guid.NewGuid();
            HistoricVehicle historicVehicle = mapVehicleToHistoricVehicle(vehicleDTO);

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                context.Vehicles.Add(vehicle);
                context.HistoricVehicles.Add(historicVehicle);
                context.SaveChanges();
            }
        }
Пример #19
0
        public void RemoveVehicle(string vin)
        {
            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                Vehicle vehicle = context.Vehicles
                                  .Where(v => v.Vin == vin)
                                  .ToList().FirstOrDefault();

                Zone zone = context.Zones
                            .Where(z => z.Vehicles.Select(v => v.Id).Contains(vehicle.Id))
                            .ToList().FirstOrDefault();
                zone.Vehicles.Remove(vehicle);
                vehicle.Status = StatusCode.ReadyToBeLocated;
                context.SaveChanges();
            }
        }
Пример #20
0
        public List <FlowStepDTO> GetAllSteps()
        {
            List <FlowStepDTO> flowStepsDTO = new List <FlowStepDTO>();

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                foreach (FlowStep flowStep in context.FlowSteps)
                {
                    FlowStepDTO flowStepDTO = new FlowStepDTO(flowStep.Name);
                    flowStepDTO.Id = flowStep.Id;
                    flowStepsDTO.Add(flowStepDTO);
                }
            }

            return(flowStepsDTO);
        }
Пример #21
0
        public void AssignZone(Guid From, Guid To)
        {
            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                Zone subZone = context.Zones
                               .Include("Vehicles")
                               .Include("SubZones")
                               .Where(z => z.Id == From)
                               .ToList().FirstOrDefault();

                Zone zone = context.Zones
                            .Include("Vehicles")
                            .Include("SubZones")
                            .Where(z => z.Id == To)
                            .ToList().FirstOrDefault();

                List <Zone> zones = context.Zones
                                    .Include("Vehicles")
                                    .Include("SubZones")
                                    .ToList();

                Zone exParentZone = zones.Find(z => z.SubZones.Contains(subZone));

                if (!zone.IsSubZone)
                {
                    int capacityLeft = GetZoneCapacityLeft(To);

                    if (subZone.MaxCapacity <= capacityLeft)
                    {
                        context.Zones.Attach(subZone);
                        zone.SubZones.Add(subZone);

                        if (exParentZone != null)
                        {
                            exParentZone.SubZones.Remove(subZone);
                        }

                        subZone.IsSubZone = true;
                        var entrySZ = context.Entry(subZone);
                        entrySZ.Property(sz => sz.IsSubZone).IsModified = true;

                        context.SaveChanges();
                    }
                }
            }
        }
Пример #22
0
        public TransportDTO FindTransportById(Guid Id)
        {
            TransportDTO transportDTO = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                Transport transport = context.Transports
                                      .Include("IdUser")
                                      .Include("Batches")
                                      .Where(t => t.Id == Id)
                                      .ToList().FirstOrDefault();
                if (transport != null)
                {
                    transportDTO = transportMapper.ToDTO(transport);
                }
                return(transportDTO);
            }
        }
Пример #23
0
        private List <Batch> GetBatches(VehicleTrackingDbContext context, List <Batch> batchesDTO)
        {
            List <Batch> batches = new List <Batch>();

            foreach (Batch batch in batchesDTO)
            {
                Batch resultbatch = new Batch();
                resultbatch = context.Batches
                              .Include("Vehicles")
                              .Include("IdUser")
                              .Where(b => b.Id == batch.Id)
                              .ToList().First();
                batches.Add(resultbatch);

                context.Batches.Attach(resultbatch);
            }
            return(batches);
        }
Пример #24
0
        public void Delete(Guid id)
        {
            Zone zone = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                var query = from z in context.Zones
                            where z.Id == id
                            select z;
                zone = query.ToList().FirstOrDefault();

                if (zone != null)
                {
                    context.Zones.Remove(zone);
                    context.SaveChanges();
                }
            }
        }
Пример #25
0
        public void DeleteStep(FlowStepDTO step)
        {
            FlowStep flowStep = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                var query = from f in context.FlowSteps
                            where f.Name == step.Name
                            select f;
                flowStep = query.ToList().FirstOrDefault();

                if (flowStep != null)
                {
                    context.FlowSteps.Remove(flowStep);
                    context.SaveChanges();
                }
            }
        }
Пример #26
0
        public void DeleteVehicleByVin(string vin)
        {
            Vehicle vehicle = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                var query = from v in context.Vehicles
                            where v.Vin == vin
                            select v;
                vehicle = query.ToList().FirstOrDefault();

                if (vehicle != null)
                {
                    context.Vehicles.Remove(vehicle);
                    context.SaveChanges();
                }
            }
        }
Пример #27
0
        public List <BatchDTO> GetAllBatches()
        {
            List <BatchDTO> batches = new List <BatchDTO>();

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                List <Batch> batchesEntities = context.Batches
                                               .Include("Vehicles")
                                               .Include("IdUser")
                                               .ToList();
                foreach (Batch batch in context.Batches)
                {
                    BatchDTO batchDTO = this.batchMapper.ToDTO(batch);
                    batches.Add(batchDTO);
                }
            }
            return(batches);
        }
Пример #28
0
        private Location GetLocation(VehicleTrackingDbContext context, string name)
        {
            Location location = context.Locations
                                .Where(l => l.Name == name)
                                .ToList().FirstOrDefault();

            if (location == null)
            {
                location      = new Location();
                location.Id   = Guid.NewGuid();
                location.Name = name;
            }
            else
            {
                context.Locations.Attach(location);
            }
            return(location);
        }
Пример #29
0
        public void UpdateTransport(TransportDTO transportDTO)
        {
            Transport transport = null;

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                var query = from t in context.Transports
                            where t.Id == transportDTO.Id
                            select t;
                transport = query.ToList().FirstOrDefault();

                if (transport != null)
                {
                    transport.EndDate   = transportDTO.EndDate;
                    transport.StartDate = transportDTO.StartDate;
                    context.SaveChanges();
                }
            }
        }
Пример #30
0
        public Guid AddBatch(BatchDTO batchDTO)
        {
            Batch batch = this.batchMapper.ToEntity(batchDTO);

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                var queryUser = from u in context.Users
                                where u.UserName == batchDTO.CreatorUserName
                                select u;
                User user = queryUser.ToList().FirstOrDefault();
                context.Users.Attach(user);

                List <Vehicle> realVehicles = new List <Vehicle>();
                foreach (Vehicle vehicle in batch.Vehicles)
                {
                    var queryVehicle = from v in context.Vehicles
                                       where v.Vin == vehicle.Vin
                                       select v;
                    Vehicle realVehicle = queryVehicle.ToList().FirstOrDefault();

                    context.Vehicles.Attach(realVehicle);
                    realVehicles.Add(realVehicle);
                    if (realVehicle.Status == StatusCode.InspectedInPort)
                    {
                        realVehicle.Status = StatusCode.ReadyToGo;
                        var entry = context.Entry(realVehicle);
                        entry.Property(sz => sz.Status).IsModified = true;

                        HistoricVehicle historicVehicle = mapVehicleToHistoricVehicle(realVehicle);
                        context.HistoricVehicles.Add(historicVehicle);
                    }
                }
                batch.Vehicles = realVehicles;
                batch.IdUser   = user;

                if (batch.Vehicles.Count > 0)
                {
                    context.Batches.Add(batch);
                    context.SaveChanges();
                }
            }
            return(batch.Id);
        }