Пример #1
0
        public IActionResult Post(PersonAccessDto p)
        {
            if ((p.BuildingId == 0) || (p.TranDate.Year == 1))
            {
                return(BadRequest());
            }

            var lastPerson = _personTrackingService.GetLastPersonTracking(p.BuildingId);

            var person = new PersonAccess
            {
                BuildingId  = p.BuildingId,
                NumberFail  = p.Failed,
                NumberPass  = p.Total - p.Failed,
                NumberTotal = p.Total,
                RemainFail  = p.Failed,
                RemainPass  = p.Total - p.Failed,
                TranDate    = p.TranDate
            };

            if ((lastPerson != null) && (lastPerson.Equals(person)))
            {
                _logger.LogWarning($"Equal previous record BuildingId:{p.BuildingId},NumberPass:{p.Total - p.Failed},NumberFail:{p.Failed},TranDate:{person.TranDate.ToLongDateString()}");
            }
            else
            {
                _logger.LogInformation($"Insert BuildingId:{p.BuildingId},NumberPass:{p.Total - p.Failed},NumberFail:{p.Failed},TranDate:{person.TranDate.ToLongDateString()}");
                _personTrackingService.InsertPersonTracking(person);
            }
            return(NoContent());
        }
Пример #2
0
        private async Task CreateOrUpdatePersonAccessAPI(int buildingId, string currentFile)
        {
            using (StreamReader file = new StreamReader(currentFile))
            {
                string tranDate = Path.GetFileNameWithoutExtension(currentFile);

                int total = Int32.Parse(file.ReadLine());
                file.ReadLine();
                int failed = Int32.Parse(file.ReadLine());

                var personTran = await GetPersonTrackingByTranDate(buildingId, tranDate);

                if (personTran != null)
                {
                    personTran.NumberFail  = failed;
                    personTran.NumberTotal = total;
                    await UpdatePersonAccessAsync(personTran);
                }
                else
                {
                    var personAccessDto = new PersonAccessDto
                    {
                        BuildingId = buildingId,
                        Total      = total,
                        Failed     = failed,
                        TranDate   = GetTranDate(currentFile)
                    };
                    await CreatePersonAccessAsync(personAccessDto);
                }
                file.Close();
            }
        }
Пример #3
0
        private async Task <Uri> CreatePersonAccessAsync(PersonAccessDto p)
        {
            string uri = $"{ConfigurationManager.AppSettings["BaseAddress"]}/api/PersonTracking";
            HttpResponseMessage response = await client
                                           .PostAsync(uri, new StringContent(JsonConvert.SerializeObject(p), Encoding.UTF8, "application/json"));

            response.EnsureSuccessStatusCode();

            // return URI of the created resource.
            return(response.Headers.Location);
        }
Пример #4
0
        private async Task CreateOrUpdatePersonAccessAPIV2(int buildingId, string ocrString, DateTime creationDate)
        {
            var ocrs   = ocrString.Split(",", StringSplitOptions.RemoveEmptyEntries);
            int total  = 0;
            int failed = 0;

            switch (ocrs.Length)
            {
            case 1:
                total = Int32.Parse(ocrs[0]);
                break;

            case 2:
                total  = Int32.Parse(ocrs[0]);
                failed = Int32.Parse(ocrs[1]);
                break;

            default:
                log.Error($"Invalid OCR string:{ocrString}.");
                return;
            }

            string tranDate   = creationDate.ToString("yyyyMMddHHmmss");
            var    personTran = await GetPersonTrackingByTranDate(buildingId, tranDate);

            if (personTran != null)
            {
                personTran.NumberFail  = failed;
                personTran.NumberTotal = total;
                await UpdatePersonAccessAsync(personTran);
            }
            else
            {
                var personAccessDto = new PersonAccessDto
                {
                    BuildingId = buildingId,
                    Total      = total,
                    Failed     = failed,
                    TranDate   = creationDate
                };
                await CreatePersonAccessAsync(personAccessDto);
            }
        }
Пример #5
0
        private async Task CreateOrUpdatePersonAccessFileV3(int buildingId, int passed, int failed, string creationDate)
        {
            var personTran = await GetPersonTrackingByTranDate(buildingId, creationDate);

            if (personTran != null)
            {
                personTran.NumberFail  = failed;
                personTran.NumberTotal = passed + failed;
                await UpdatePersonAccessAsync(personTran);
            }
            else
            {
                var personAccessDto = new PersonAccessDto
                {
                    BuildingId = buildingId,
                    Failed     = failed,
                    Total      = failed + passed,
                    TranDate   = GetTranDate(creationDate)
                };
                await CreatePersonAccessAsync(personAccessDto);
            }
        }