示例#1
0
        public async Task <TimestampResponseModel> ClockOutAsync(TimestampModel model)
        {
            var response = new TimestampResponseModel();

            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                response.Succeeded = false;
                response.Message   = "No User Found";
                return(response);
            }

            // Find an active timestamp
            var timestamp = user.Timestamps.Single(timestamp => timestamp.IsActive);

            if (timestamp == null)
            {
                response.Succeeded = false;
                response.Message   = "No Active Timestamp";
                return(response);
            }

            timestamp.IsActive           = false;
            timestamp.Out                = model.ClockTime;
            timestamp.OutWhileOnPremises = IsEmployeeOnPremises(model.ClockLocation);
            _context.Update(user);
            _context.SaveChanges();

            // Generate a response for the user
            response.Succeeded = true;
            response.Message   = "Clocked out successfully";
            return(response);
        }
示例#2
0
        public async Task <TimestampResponseModel> ClockInAsync(TimestampModel model)
        {
            var response = new TimestampResponseModel();

            // Use the email to get the user object from the database
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                response.Succeeded = false;
                response.Message   = "User Not Found";
                return(response);
            }

            // Create a timestamp object and add it to the list associated with the user's
            var timestamp = new Timestamp
            {
                In = model.ClockTime,
                InWhileOnPremises = IsEmployeeOnPremises(model.ClockLocation),
                IsActive          = true
            };

            user.Timestamps.Add(timestamp);
            _context.Update(user);
            _context.SaveChanges();

            // Generate a response for the user
            response.Succeeded = true;
            response.Message   = "Clocked in successfully";
            return(response);
        }
示例#3
0
        public async Task <IActionResult> ClockOutAsync(TimestampModel model)
        {
            var result = await _userService.ClockOutAsync(model);

            return(Ok(result));
        }