コード例 #1
0
        ///<inheritdoc/>
        public DetectedLicensePlate InsertNewDetectedPlate(string plateNumber, DateTime detectedDateTime, int camId,
                                                           string imgUrl, double confidence)
        {
            if (!plateNumber.IsValidPlateNumber())
            {
                throw new ArgumentException(Resources.Error_PlateNumberFomatInvalid);
            }

            if (confidence < 0 || confidence > 100)
            {
                // It seems like I can't edit resource file on Rider
                throw new ArgumentException(string.Format($"The confidence parameter must be between 0 and 100, is: {confidence}"));
            }
            var detectedPlateToInsert = new DetectedLicensePlate()
            {
                PlateNumber      = plateNumber,
                DetectedDateTime = detectedDateTime,
                CamId            = camId,
                ImgUrl           = imgUrl,
                Confidence       = confidence
            };

            using (var ctx = _dbContextFactory.BuildHucaresContext())
            {
                ctx.DetectedLicensePlates.Add(detectedPlateToInsert);
                ctx.SaveChanges();
            }

            return(detectedPlateToInsert);
        }
コード例 #2
0
        public MissingLicensePlate InsertPlateRecord(string plateNumber, DateTime searchStartDatetime)
        {
            if (!plateNumber.IsValidPlateNumber())
            {
                throw new ArgumentException(Resources.Error_PlateNumberFomatInvalid);
            }

            var missingPlateObj = new MissingLicensePlate()
            {
                PlateNumber         = plateNumber,
                SearchStartDateTime = searchStartDatetime,
                Status = LicensePlateFoundStatus.Searching
            };

            using (var ctx = _dbContextFactory.BuildHucaresContext())
            {
                if (ctx.MissingLicensePlates.Any(m => m.PlateNumber == plateNumber &&
                                                 m.Status == LicensePlateFoundStatus.Searching))
                {
                    throw new Exception(Resources.Error_MissingPlateExists);
                }

                ctx.MissingLicensePlates.Add(missingPlateObj);
                ctx.SaveChanges();
            }

            return(missingPlateObj);
        }
コード例 #3
0
ファイル: CameraInfoHelper.cs プロジェクト: AinoraZ/hucares
        /// <summary>
        /// Deletes the camera record from the DB CameraInfo table.
        /// This should only succeed if no dependencies exist in DetectedLicensePlates DB table.
        /// </summary>
        /// <param name="id"> Id of the record in the DB CameraInfo table </param>
        /// <returns> The deleted CameraInfo instance </returns>
        public CameraInfo DeleteCameraById(int id)
        {
            if (_detectedPlateHelper.GetAllDetectedPlatesByCamera(id).Any())
            {
                throw new AccessViolationException(Resources.Error_CannotDeleteCamera);
            }
            using (var ctx = _dbContextFactory.BuildHucaresContext())
            {
                var recordToDelete = ctx.CameraInfo.Where(c => c.Id == id).FirstOrDefault() ??
                                     throw new ArgumentException(string.Format(Resources.Error_BadIdProvided, id));


                ctx.CameraInfo.Remove(recordToDelete);
                ctx.SaveChanges();

                return(recordToDelete);
            }
        }