Пример #1
0
        internal string CheckTralerAndTruckDb(string token)
        {
            string plates = null;
            Driver driver = context.Drivers.Where(d => d.Token == token)
                            .Include(d => d.InspectionDrivers)
                            .FirstOrDefault();
            InspectionDriver inspectionDriver = driver.InspectionDrivers.Count != 0 ? driver.InspectionDrivers.Last() : null;

            if (inspectionDriver != null)
            {
                List <Truck>   trucks   = context.Trucks.ToList();
                List <Trailer> trailers = context.Trailers.ToList();
                DateTime       dateTime = Convert.ToDateTime(inspectionDriver.Date);
                if (dateTime.Date == DateTime.Now.Date)
                {
                    Truck   truck        = trucks.FirstOrDefault(t => t.Id == inspectionDriver.IdITruck);
                    Trailer trailer      = trailers.FirstOrDefault(t => t.Id == inspectionDriver.IdITrailer);
                    string  plateTruck   = truck != null ? truck.PlateTruk : "";
                    string  plateTrailer = trailer != null ? trailer.Plate : "";
                    plates = $"{plateTruck},{plateTrailer}";
                }
                else
                {
                    plates = ",";
                }
            }
            else
            {
                plates = ",";
            }
            return(plates);
        }
Пример #2
0
        public int GetIndexDb(string token)
        {
            int    indexPhoto = 0;
            Driver driver     = context.Drivers.Where(d => d.Token == token)
                                .Include(d => d.InspectionDrivers)
                                .FirstOrDefault();

            if (driver.InspectionDrivers != null && driver.InspectionDrivers.Count != 0)
            {
                InspectionDriver inspectionDrivers = driver.InspectionDrivers.FirstOrDefault(i => DateTime.Parse(i.Date).Date == DateTime.Now.Date);
                if (inspectionDrivers == null)
                {
                    indexPhoto = 1;
                }
                else
                {
                    if (inspectionDrivers.IdITrailer != 0)
                    {
                        indexPhoto = inspectionDrivers.CountPhotoTrailer + 1;
                    }
                    else
                    {
                        indexPhoto = inspectionDrivers.CountPhotoTruck + 1;
                    }
                }
            }
            else
            {
                indexPhoto = 1;
            }
            return(indexPhoto);
        }
Пример #3
0
        public string GetInspectionDriverIndb(string token)
        {
            string           statusAndTimeInInspection = null;
            Driver           driver           = context.Drivers.Include(d => d.InspectionDrivers).FirstOrDefault(d => d.Token == token);
            InspectionDriver inspectionDriver = driver.InspectionDrivers != null && driver.InspectionDrivers.Count != 0 ? driver.InspectionDrivers.Last() : null;

            if (inspectionDriver == null)
            {
                driver.IsInspectionDriver      = false;
                driver.IsInspectionToDayDriver = false;
            }
            else if (Convert.ToDateTime(inspectionDriver.Date).Date != DateTime.Now.Date)
            {
                if (DateTime.Now.Hour >= 12)
                {
                    driver.IsInspectionDriver      = false;
                    driver.IsInspectionToDayDriver = false;
                }
                else if (DateTime.Now.Hour <= 12 && 6 >= DateTime.Now.Hour)
                {
                    driver.IsInspectionDriver      = true;
                    driver.IsInspectionToDayDriver = false;
                }
            }
            context.SaveChanges();
            if (driver.IsInspectionDriver)
            {
                if (driver.IsInspectionToDayDriver)
                {
                    statusAndTimeInInspection = "true,true,0";
                }
                else
                {
                    string TimOfInsection = "";
                    if ((12 - DateTime.Now.Hour) < 0 || DateTime.Now.Hour < 5)
                    {
                        TimOfInsection = "0";
                    }
                    else
                    {
                        TimOfInsection = (12 - DateTime.Now.Hour).ToString();
                    }
                    statusAndTimeInInspection = "true,false," + TimOfInsection;
                }
            }
            else
            {
                if (driver.IsInspectionToDayDriver)
                {
                    statusAndTimeInInspection = "false,true,0";
                }
                else
                {
                    statusAndTimeInInspection = "false,false,0";
                }
            }
            statusAndTimeInInspection += $",{driver.Id}";
            return(statusAndTimeInInspection);
        }
Пример #4
0
        public async Task SetInspectionDriverInDb(string idDriver, InspectionDriver inspectionDriver)
        {
            Driver driver = await context.Drivers.Where(d => d.Id == Convert.ToUInt32(idDriver))
                            .Include(d => d.InspectionDrivers)
                            .FirstOrDefaultAsync();

            if (driver.InspectionDrivers == null)
            {
                driver.InspectionDrivers = new List <InspectionDriver>();
            }
            driver.InspectionDrivers.Add(inspectionDriver);
            await context.SaveChangesAsync();
        }
Пример #5
0
        internal void SetPlateTrailer(int id, string idDriver)
        {
            Driver driver = context.Drivers.Include(d => d.InspectionDrivers)
                            .FirstOrDefault(d => d.Id == Convert.ToInt32(idDriver));
            InspectionDriver inspectionDrivers = driver.InspectionDrivers.FirstOrDefault(i => DateTime.Parse(i.Date).Date == DateTime.Now.Date);

            if (inspectionDrivers != null)
            {
                Trailer trailer = context.Trailers.First(t => t.Id == id);
                inspectionDrivers.IdITruck = trailer.Id;
                context.SaveChanges();
            }
        }
Пример #6
0
        public async Task UpdateInspectionDriver(string idDriver)
        {
            Driver driver = await context.Drivers.Where(d => d.Id == Convert.ToUInt32(idDriver))
                            .Include(d => d.InspectionDrivers)
                            .FirstOrDefaultAsync();

            driver.LastDateInspaction = DateTime.Now.ToString();
            InspectionDriver inspectionDriver = driver.InspectionDrivers.Last();

            inspectionDriver.Date          = DateTime.Now.ToString();
            driver.IsInspectionDriver      = true;
            driver.IsInspectionToDayDriver = true;
            await context.SaveChangesAsync();
        }
Пример #7
0
        internal string GetPlateTruckByTokenDriver(string token)
        {
            string plateTrailer = null;
            Driver driver       = context.Drivers
                                  .Include(d => d.InspectionDrivers)
                                  .First(d => d.Token == token);
            InspectionDriver inspectionDriver = driver.InspectionDrivers.Count != 0 ? driver.InspectionDrivers.Last() : null;

            if (inspectionDriver != null && inspectionDriver.IdITruck != 0)
            {
                plateTrailer = context.Trucks.FirstOrDefault(t => t.Id == inspectionDriver.IdITruck) != null?context.Trucks.FirstOrDefault(t => t.Id == inspectionDriver.IdITruck).PlateTruk : null;
            }
            return(plateTrailer);
        }
Пример #8
0
        internal string GetLastInspaction(string idDriver)
        {
            string lastInspectionDriver = null;
            Driver driver = context.Drivers.Where(d => d.Id.ToString() == idDriver)
                            .Include(d => d.InspectionDrivers)
                            .FirstOrDefault();

            if (driver.InspectionDrivers != null && driver.InspectionDrivers.Count != 0)
            {
                InspectionDriver inspectionDriver = driver.InspectionDrivers.Last();
                Truck            truck            = context.Trucks.FirstOrDefault(t => t.Id == inspectionDriver.IdITruck);
                Trailer          trailer          = context.Trailers.FirstOrDefault(t => t.Id == inspectionDriver.IdITrailer);
                lastInspectionDriver = inspectionDriver.Date.Remove(inspectionDriver.Date.IndexOf(" ") + 1);
                if (truck != null)
                {
                    lastInspectionDriver += $",{truck.PlateTruk}";
                }
                if (trailer != null)
                {
                    lastInspectionDriver += $",{trailer.Plate}";
                }
            }
            return(lastInspectionDriver);
        }
Пример #9
0
        public async Task <bool> ChechToDayInspactionInDb(string token)
        {
            bool   isInspaction = false;
            Driver driver       = await context.Drivers.Where(d => d.Token == token)
                                  .Include(d => d.InspectionDrivers)
                                  .FirstOrDefaultAsync();

            if (driver.InspectionDrivers != null && driver.InspectionDrivers.Count != 0)
            {
                InspectionDriver inspectionDriver = driver.InspectionDrivers.Last();
                DateTime         dateTime         = Convert.ToDateTime(inspectionDriver.Date);
                Truck            truck            = context.Trucks.FirstOrDefault(t => t.Id == inspectionDriver.IdITruck);
                Trailer          trailer          = context.Trailers.FirstOrDefault(t => t.Id == inspectionDriver.IdITruck);
                int countImageTruck = truck != null?GetTransportVehicle(truck.TypeTruk).CountPhoto : 0;

                int countImageTrailer = trailer != null?GetTransportVehicle(trailer.Type).CountPhoto : 0;

                if (dateTime.Date != DateTime.Now.Date || (inspectionDriver.CountPhotoTruck + inspectionDriver.CountPhotoTrailer <= countImageTruck + countImageTrailer))
                {
                    isInspaction = false;
                }
                else
                {
                    driver.IsInspectionToDayDriver = true;
                    driver.IsInspectionDriver      = true;
                    isInspaction = true;
                }
            }
            else
            {
                isInspaction = false;
            }
            await context.SaveChangesAsync();

            return(isInspaction);
        }
Пример #10
0
        internal bool SetTralerAndTruck(string token, string plateTrailer, string plateTruck, string nowCheck)
        {
            Truck   truck   = context.Trucks.FirstOrDefault(t => t.PlateTruk == plateTruck);
            Trailer trailer = context.Trailers.FirstOrDefault(t => t.Plate == plateTrailer);

            if (truck == null && trailer == null)
            {
                return(false);
            }
            if (nowCheck == "Truck")
            {
                if (truck == null)
                {
                    return(false);
                }
            }
            else if (nowCheck == "Trailer")
            {
                if (trailer == null)
                {
                    return(false);
                }
            }
            Driver driver = context.Drivers
                            .Include(d => d.InspectionDrivers)
                            .First(d => d.Token == token);
            InspectionDriver inspectionDriver = driver.InspectionDrivers.Count != 0 ? driver.InspectionDrivers.Last() : null;

            if (inspectionDriver != null && Convert.ToDateTime(inspectionDriver.Date).Date == DateTime.Now.Date)
            {
                if (truck != null)
                {
                    inspectionDriver.IdITruck = truck.Id;
                }
                if (trailer != null)
                {
                    inspectionDriver.IdITrailer = trailer.Id;
                }
            }
            else
            {
                if (truck != null)
                {
                    driver.InspectionDrivers.Add(new InspectionDriver()
                    {
                        IdITruck          = truck.Id,
                        Date              = DateTime.Now.ToString(),
                        CountPhotoTruck   = 0,
                        CountPhotoTrailer = 0
                    });
                }
                if (trailer != null)
                {
                    driver.InspectionDrivers.Add(new InspectionDriver()
                    {
                        IdITrailer        = trailer.Id,
                        Date              = DateTime.Now.ToString(),
                        CountPhotoTruck   = 0,
                        CountPhotoTrailer = 0
                    });
                }
            }
            context.SaveChanges();
            return(true);
        }
Пример #11
0
        public async Task SaveInspectionDriverInDb(string idDriver, PhotoDriver photo, int IndexPhoto, string typeTransportVehicle)
        {
            try
            {
                Driver driver = context.Drivers.Include(d => d.InspectionDrivers)
                                .FirstOrDefault(d => d.Id == Convert.ToInt32(idDriver));
                if (driver.InspectionDrivers != null && driver.InspectionDrivers.Count != 0)
                {
                    InspectionDriver inspectionDrivers = driver.InspectionDrivers.FirstOrDefault(i => DateTime.Parse(i.Date).Date == DateTime.Now.Date);
                    if (inspectionDrivers == null)
                    {
                        inspectionDrivers             = new InspectionDriver();
                        inspectionDrivers.Date        = DateTime.Now.ToString();
                        inspectionDrivers.PhotosTruck = new List <PhotoDriver>();
                        driver.InspectionDrivers.Add(inspectionDrivers);
                    }
                    await context.SaveChangesAsync();

                    photo.IdInspaction = inspectionDrivers.Id;
                    //To do добавить раздилитель индех фото по тракам трейлерам
                    photo.IndexPhoto = IndexPhoto;
                    inspectionDrivers.PhotosTruck = context.PhotoDrivers.Where(p => p.IdInspaction == inspectionDrivers.Id).ToList();
                    if (inspectionDrivers.PhotosTruck.FirstOrDefault(p => p.IndexPhoto == IndexPhoto) == null)
                    {
                        if (typeTransportVehicle == "Truck")
                        {
                            inspectionDrivers.CountPhotoTruck++;
                        }
                        else if (typeTransportVehicle == "Trailer")
                        {
                            inspectionDrivers.CountPhotoTrailer++;
                        }
                        inspectionDrivers.PhotosTruck.Add(photo);
                    }
                    await context.SaveChangesAsync();
                }
                else
                {
                    InspectionDriver inspectionDrivers = new InspectionDriver();
                    driver.InspectionDrivers      = new List <InspectionDriver>();
                    inspectionDrivers.Date        = DateTime.Now.ToString();
                    inspectionDrivers.PhotosTruck = new List <PhotoDriver>();

                    if (typeTransportVehicle == "Truck")
                    {
                        inspectionDrivers.CountPhotoTruck++;
                    }
                    else if (typeTransportVehicle == "Trailer")
                    {
                        inspectionDrivers.CountPhotoTrailer++;
                    }
                    inspectionDrivers.PhotosTruck.Add(photo);
                    driver.InspectionDrivers.Add(inspectionDrivers);
                    await context.SaveChangesAsync();

                    photo.IdInspaction = inspectionDrivers.Id;
                    await context.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
            }
        }