コード例 #1
0
        public JsonResult Punch(PunchInputModel inputModel)
        {
            var employee = _employeeRepository.FindEmployeeById("1", inputModel.Serial);
            var response = new PunchResponseModel();

            if (employee == null)
            {
                response.Result = (int)PunchResult.Error;
                return Json(response);
            }

            response.Result = (int)PunchResult.Success;
            response.Name = String.Format("{0} {1}", employee.FirstName, employee.LastName);

            // already logged in?
            if (employee.TimeIn.HasValue)
            {
                var punch = new Punch();
                punch.RowKey = Guid.NewGuid().ToString();
                punch.SerialNumber = employee.SerialNumber;
                punch.TimeIn = employee.TimeIn.Value;
                punch.TimeOut = DateTime.UtcNow;
                _punchUnitOfWork.Initialize();
                _punchUnitOfWork.Insert(punch);
                _punchUnitOfWork.Execute();
                employee.TimeIn = null;
                response.Direction = -1;
            }
            else
            {
                employee.TimeIn = DateTime.UtcNow;
                response.Direction = 1;
            }

            _employeeUnitOfWork.Initialize();
            _employeeUnitOfWork.InsertOrReplace(employee);
            _employeeUnitOfWork.Execute();

            return Json(response);
        }
コード例 #2
0
 public EmployeePunchModel(Punch source)
 {
     this.TimeIn = TimeZoneInfo.ConvertTimeFromUtc(source.TimeIn, TimeZoneInfo.Local);
     this.TimeOut = TimeZoneInfo.ConvertTimeFromUtc(source.TimeOut, TimeZoneInfo.Local);
 }