Exemplo n.º 1
0
        public async Task SaveInspactionDriver(string idDriver, string photoJson, int indexPhoto, string typeTransportVehicle)
        {
            photoJson = photoJson.Insert(photoJson.IndexOf(idDriver) + 2, $"{DateTime.Now.ToShortDateString()}/");
            PhotoDriver photo = JsonConvert.DeserializeObject <PhotoDriver>(photoJson);
            await sqlCommandApiMobile.SaveInspectionDriverInDb(idDriver, photo, indexPhoto, typeTransportVehicle);

            //await Task.Run(() =>
            //{
            //    IDetect detect = null;
            //    if(indexPhoto == 1 || indexPhoto == 2 || indexPhoto == 26 || indexPhoto == 13)
            //    {
            //        detect = new DerectTruck();
            //    }
            //    else if(indexPhoto == 34 || indexPhoto == 35 || indexPhoto == 38)
            //    {
            //        detect = new DetectTrailers();
            //    }
            //    if(detect != null)
            //    {
            //        detect.AuchGoole(sqlCommandApiMobile);
            //        detect.DetectText(idDriver, photo.path);
            //    }
            //});
        }
Exemplo n.º 2
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)
            {
            }
        }