Ejemplo n.º 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());
        }
Ejemplo n.º 2
0
        private void InsertPersonAccess(int buildingId, int total, int failed, DateTime tranDate)
        {
            var lastPerson = _personTrackingService.GetLastPersonTracking(buildingId);

            int remainFail;
            int remainPass;
            int remainTotal;

            if (lastPerson != null)
            {
                if (total > lastPerson.NumberTotal)
                {
                    remainTotal = total - lastPerson.NumberTotal;
                    remainFail  = failed - lastPerson.NumberPass;
                    remainPass  = remainTotal - remainFail;
                }
                else
                {
                    remainTotal = total;
                    remainFail  = failed;
                    remainPass  = remainTotal - remainFail;
                }
            }
            else
            {
                remainPass = total - failed;
                remainFail = failed;
            }

            var person = new PersonAccess
            {
                BuildingId  = buildingId,
                NumberFail  = failed,
                NumberPass  = total - failed,
                NumberTotal = total,
                RemainFail  = remainFail,
                RemainPass  = remainPass,
                TranDate    = tranDate
            };

            log.Info($"Insert BuildingId:{buildingId},NumberPass:{total - failed},NumberFail:{failed},TranDate:{person.TranDate.ToShortTimeString()}");
            _personTrackingService.InsertPersonTracking(person);
        }