Exemplo n.º 1
0
        public HttpResponseMessage saveShiftForUser([FromBody] ShiftViewModel shiftDetails)
        {
            IEnumerable <StudentTimesheetsViewModel>  result             = null;
            IEnumerable <OverlappingShiftIdViewModel> overlapCheckResult = null;

            int userID            = GetCurrentUserID();
            var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
            var username          = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;

            try
            {
                if (shiftDetails.SHIFT_START_DATETIME == null || shiftDetails.SHIFT_END_DATETIME == null || shiftDetails.SHIFT_START_DATETIME == shiftDetails.SHIFT_END_DATETIME)
                {
                    _errorLogService.Log($"Invalid timesheets shift saved. Student ID: {shiftDetails.ID}, job ID: {shiftDetails.EML}, shiftStart: {shiftDetails.SHIFT_START_DATETIME}, shift end time: {shiftDetails.SHIFT_END_DATETIME}, hours worked: {shiftDetails.HOURS_WORKED} at time {DateTime.Now}");
                    throw new Exception("Invalid shift times. shiftStart and shiftEnd must be non-null and not the same.");
                }
                ;

                overlapCheckResult = _jobsService.checkForOverlappingShift(userID, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME);
                if (overlapCheckResult.Count() > 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.Conflict, "Error: shift overlap detected"));
                }
                result = _jobsService.saveShiftForUser(userID, shiftDetails.EML, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME, shiftDetails.HOURS_WORKED, shiftDetails.SHIFT_NOTES, username);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Exemplo n.º 2
0
        public IHttpActionResult Post([FromBody] string error_message)
        {
            if (error_message == null)
            {
                throw new BadInputException();
            }

            var result = _errorLogService.Log(error_message);

            return(Created("error log", result));
        }