Ejemplo n.º 1
0
        public IHttpActionResult PostShiftCheck(ShiftCheck shiftCheck)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ShiftCheck.Add(shiftCheck);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ShiftCheckExists(shiftCheck.ProcessOrderNo))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = shiftCheck.ProcessOrderNo }, shiftCheck));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutShiftCheck(int id, ShiftCheck shiftCheck)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != shiftCheck.ProcessOrderNo)
            {
                return(BadRequest());
            }

            db.Entry(shiftCheck).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShiftCheckExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetShiftCheck(int id)
        {
            ShiftCheck shiftCheck = db.ShiftCheck.Find(id);

            if (shiftCheck == null)
            {
                return(NotFound());
            }

            return(Ok(shiftCheck));
        }
Ejemplo n.º 4
0
        public IHttpActionResult DeleteShiftCheck(int id)
        {
            ShiftCheck shiftCheck = db.ShiftCheck.Find(id);

            if (shiftCheck == null)
            {
                return(NotFound());
            }

            db.ShiftCheck.Remove(shiftCheck);
            db.SaveChanges();

            return(Ok(shiftCheck));
        }
        private void ShowLastCheck(ShiftCheck shiftCheck)
        {
            View.FullName      = shiftCheck.Employee.FullName;
            View.Post          = shiftCheck.Employee.Post.Name;
            View.DateTimeEntry = shiftCheck.DateTimeEntry;
            View.DateTimeExit  = shiftCheck.DateTimeExit;
            View.CheckPhoto    = _webCamera.Snapshot;
            var empPhotoPath = Path.Combine(Properties.Settings.Default.EmployeePhotoFolder,
                                            string.Format($"{shiftCheck.Employee.FullName}-{shiftCheck.Employee.BarCode}.jpg"));

            if (File.Exists(empPhotoPath))
            {
                View.EmployeePhoto = Image.FromFile(empPhotoPath);
            }
        }
Ejemplo n.º 6
0
        public ShiftCheck Check()
        {
            ShiftCheck shiftCheck;

            if (_employeeRepository.GetOne(_barCode) == null)
            {
                return(null);
            }

            if (_isEntry)
            {
                shiftCheck = new ShiftCheck()
                {
                    BarCode       = _barCode,
                    DateTimeEntry = DateTime.Now,
                };
                _shiftCheckRepository.Add(shiftCheck);
            }
            else
            {
                shiftCheck = _shiftCheckRepository.GetLastEntryByBarCode(_barCode);
                if (shiftCheck == null ||
                    shiftCheck.DateTimeExit.HasValue ||
                    shiftCheck.DateTimeEntry.HasValue &&
                    DateTime.Now - shiftCheck.DateTimeEntry.Value >
                    TimeSpan.FromHours(Properties.Settings.Default.MaxShiftInHours))
                {
                    shiftCheck = new ShiftCheck()
                    {
                        BarCode      = _barCode,
                        DateTimeExit = DateTime.Now,
                    };
                    _shiftCheckRepository.Add(shiftCheck);
                }
                else
                {
                    shiftCheck.DateTimeExit = DateTime.Now;
                    _shiftCheckRepository.Update(shiftCheck);
                }
            }
            _shiftCheckRepository.LoadAllIncludes(shiftCheck);
            return(shiftCheck);
        }
        private void SaveCheckPhoto(ShiftCheck shiftCheck)
        {
            var way  = View.IsEntry ? 1 : 2;
            var path = Path.Combine(Properties.Settings.Default.CheckPhotoFolder,
                                    $"{DateTime.Now:dd.MM.yyyy}");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path = Path.Combine(path, string.Format($"{shiftCheck.Employee.FullName}_{shiftCheck.ShiftCheckId}_{way}.jpg"));
            if (View.IsEntry)
            {
                _webCamera.SaveImageToFile(path, $"Entry - {DateTime.Now:dd.MM.yyyy HH:mm:ss}", Color.LimeGreen);
            }
            else
            {
                _webCamera.SaveImageToFile(path, $"Exit - {DateTime.Now:dd.MM.yyyy HH:mm:ss}", Color.Blue);
            }
        }
        private void CheckShiftHours(ShiftCheck check)
        {
            // variable that will change to calculate hours
            DateTime currentDate = check.DateTimeEntry ?? check.DateTimeExit ?? DateTime.MaxValue;
            DateTime endDate     = check.DateTimeExit ?? check.DateTimeEntry ?? DateTime.MinValue;
            TimeSpan periodStart = new TimeSpan();
            TimeSpan periodEnd   = new TimeSpan();
            int      round       = 1;

            while (true)
            {
                // Check the period to compare
                switch (round)
                {
                case 1:
                    periodStart = TimeSpan.FromHours(0);
                    periodEnd   = _startOfDayShift;
                    break;

                case 2:
                    periodStart = _startOfDayShift;
                    periodEnd   = _endOfDayShift;
                    break;

                case 3:
                    periodStart = _endOfDayShift;
                    periodEnd   = TimeSpan.Parse("23:59:59.9999999");
                    break;
                }

                // check if variable is in a given period
                if (currentDate.TimeOfDay >= periodStart &&
                    currentDate.TimeOfDay < periodEnd)
                {
                    var temp = currentDate.Date + periodEnd;
                    // if this is the last check loop must be stopped
                    if (temp >= endDate)
                    {
                        temp = endDate;
                        var hours = (int)Math.Round((temp - currentDate).TotalMinutes / 60);
                        AddShiftRecord(check.BarCode, check.Employee.FullName, check.Employee.Post.Name, temp, round,
                                       hours);
                        return;
                    }
                    // if not then add shift record and displace variable to the next period
                    else
                    {
                        var hours = (int)Math.Round((temp - currentDate).TotalMinutes / 60);
                        AddShiftRecord(check.BarCode, check.Employee.FullName, check.Employee.Post.Name, temp, round,
                                       hours);
                        currentDate = currentDate.Date + periodEnd;
                    }
                }

                round++;
                // if it was the last check of day then variable displace to the next day
                if (round == 4)
                {
                    round       = 1;
                    currentDate = currentDate.Date.AddDays(1);
                }
            }
        }