/// <summary> /// /// </summary> /// <param name="userId"></param> /// <param name="activityId"></param> /// <param name="employeeName"></param> /// <returns></returns> public bool InsertTimeOut(ClockOutQueryModel clockOut) { DailyTimeOut newRecord = new DailyTimeOut(); try { using (TimeInEntities context = new TimeInEntities()) { newRecord.EmployeeId = clockOut.UserId; newRecord.ActivityCd = clockOut.ActivityId; newRecord.TimeOutDttm = clockOut.ClockOutDateTime; newRecord.IsActive = true; newRecord.CreateDttm = DateTime.Now; newRecord.CreateUserId = clockOut.UserName; newRecord.UpdateDttm = DateTime.Now; newRecord.UpdateUserId = clockOut.UserName; context.DailyTimeOuts.Add(newRecord); context.SaveChanges(); } } catch (Exception ex) { return(false); } return(true); }
public string ClockOutEmployee(ClockOutQueryModel clockOut) { if (clockOut == null) { return("No data is being processed."); } if (string.IsNullOrEmpty(clockOut.UserName) || clockOut.UserId < 10000) { return("User not found."); } if (clockOut.ClockOutDateTime < DateTime.Parse("1900-01-01") || clockOut.ClockOutDateTime > DateTime.Now) { return("Date is out of bounds."); } if (clockOut.ActivityId == 0) { return("Activity ID not found."); } bool isSuccess = _dataAccess.InsertTimeOut(clockOut); if (isSuccess) { return("Employee successfully clocked out."); } return(String.Empty); }
public IHttpActionResult ClockOutEmployee([FromBody] ClockOutModel clockOut) { var container = ContainerConfig.Configure(); User userQuery = new User(); Activity activityQuery = new Activity(); if (clockOut == null) { return(Json(new { Result = "Internal server error.", StatusCode = HttpStatusCode.InternalServerError })); } using (var scope = container.BeginLifetimeScope()) { var app = scope.Resolve <IUserDataAccess>(); userQuery = app.GetUser(clockOut.UserName); if (userQuery == null) { return(Json(new { Result = "Employee record not found." })); } } using (var scope = container.BeginLifetimeScope()) { var app = scope.Resolve <IActivityDataAccess>(); activityQuery = app.GetActivitySingle(clockOut.ActivityId); if (activityQuery == null) { return(Json(new { Result = "Activity selected is unknown." })); } } using (var scope = container.BeginLifetimeScope()) { var app = scope.Resolve <ITimeOutEmployeeAttendance>(); ClockOutQueryModel clockQuery = new ClockOutQueryModel { UserId = userQuery.UserKey, UserName = clockOut.UserName, ActivityId = activityQuery.ActivityId, ClockOutDateTime = DateTime.Parse(clockOut.ClockOutDateTime) }; string clockOutResult = app.ClockOutEmployee(clockQuery); return(Json(new { Result = clockOutResult })); } }
public void ClockOutEmployeeTest_WhenReportMonthIsOutOfMaximumBounds_ReturnsReportMonthIsOutOfBoundsError() { ClockOutQueryModel input = new ClockOutQueryModel { UserId = 10001, UserName = "******", ActivityId = 1, ClockOutDateTime = DateTime.Now.AddMonths(1) }; Mock <IDailyTimeOutDataAccess> mock = new Mock <IDailyTimeOutDataAccess>(); mock.Setup(x => x.InsertTimeOut(input)).Returns(true); ITimeOutEmployeeAttendance app = new TimeOutEmployeeAttendance(mock.Object); string output = app.ClockOutEmployee(input); Assert.AreEqual("Date is out of bounds.", output); }
public void ClockOutEmployeeTest_WhenEmployeeUserIdIsZero_ReturnsUserNotFoundError() { ClockOutQueryModel input = new ClockOutQueryModel { UserId = 0, UserName = "******", ActivityId = 1, ClockOutDateTime = DateTime.Now }; Mock <IDailyTimeOutDataAccess> mock = new Mock <IDailyTimeOutDataAccess>(); mock.Setup(x => x.InsertTimeOut(input)).Returns(true); ITimeOutEmployeeAttendance app = new TimeOutEmployeeAttendance(mock.Object); string output = app.ClockOutEmployee(input); Assert.AreEqual("User not found.", output); }
public void ClockOutEmployeeTest_WhenUserNameAndReportDateIsCorrect_ReturnsSuccessMessage() { ClockOutQueryModel input = new ClockOutQueryModel { UserId = 10001, UserName = "******", ActivityId = 1, ClockOutDateTime = DateTime.Now }; Mock <IDailyTimeOutDataAccess> mock = new Mock <IDailyTimeOutDataAccess>(); mock.Setup(x => x.InsertTimeOut(input)).Returns(true); ITimeOutEmployeeAttendance app = new TimeOutEmployeeAttendance(mock.Object); string output = app.ClockOutEmployee(input); Assert.AreEqual("Employee successfully clocked out.", output); }