Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public async Task <TimestampResponseModel> GetActiveClockAsync(string email)
        {
            var response = new TimestampResponseModel();
            var user     = await _userManager.FindByEmailAsync(email);

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

            var anyActiveTimestamp = user.Timestamps.Any(timestamp => timestamp.IsActive);

            if (anyActiveTimestamp)
            {
                response.Succeeded     = true;
                response.IsClockActive = true;
                response.Message       = "Active clock found";
                return(response);
            }
            else
            {
                response.Succeeded     = true;
                response.IsClockActive = false;
                response.Message       = "No Active Clock Found";
                return(response);
            }
        }