Exemplo n.º 1
0
        public DateTime PunchIn()
        {
            _currentFile = GetFile();
            if (_currentFile.Exists())
            {
                _currentMonth = _currentFile.Load();
            }
            else
            {
                _currentMonth = new PunchMonth {
                    Year = DateTime.Now.Year, Month = DateTime.Now.Month
                }
            };
            var      today = DateTime.Now.Day;
            PunchDay day;

            if (_currentMonth.Days.ContainsKey(today))
            {
                day = _currentMonth.Days[today];
            }
            else
            {
                day = new PunchDay {
                    Day = today
                };
                _currentMonth.Days[today] = day;
            }

            _currentEntry = new PunchEntry {
                PunchIn = DateTime.Now
            };
            day.Entries.Add(_currentEntry);
            _currentFile.Save(_currentMonth);
            return(_currentEntry.PunchIn);
        }
Exemplo n.º 2
0
        public TimeSpan PunchOut()
        {
            if (_currentEntry != null)
            {
                _currentEntry.PunchOut = DateTime.Now;
                _currentFile.Save(_currentMonth);
                return(_currentEntry.Duration);
            }

            _currentFile  = null;
            _currentMonth = null;
            _currentEntry = null;
            return(new TimeSpan());
        }