Example #1
0
        public virtual HttpResponseMessage Delete([FromBody] TimeKeepEntry value)
        {
            try
            {
                if (!ValidateUser(RequestContext.Principal, value))
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.Forbidden, userNotAllowed));
                }
                if (value == null)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, MissingOrInvalidRequestBody));
                }
                if (!value.ID.HasValue)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, idIsNull));
                }

                TimeKeepEntry find = TimeKeepEntry.Read(value.ID.Value);
                if (find == null)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.NotFound, noEntries));
                }

                value.Delete();
                return(Request.CreateResultResponse <TimeKeepEntry>(value));
            }
            catch (Exception ex)
            {
                return(Request.CreateCustomErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Example #2
0
        public virtual HttpResponseMessage Put([FromBody] TimeKeepEntry value)
        {
            try
            {
                if (!ValidateUser(RequestContext.Principal, value))
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.Forbidden, userNotAllowed));
                }
                if (value == null)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, MissingOrInvalidRequestBody));
                }
                if (!value.ID.HasValue)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, idIsNull));
                }
                if (value.User == null || value.User.Trim().Length == 0)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, userIsNull));
                }
                if (value.EndTime.HasValue && value.EndTime.Value <= value.StartTime)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, EndDateAtOrBeforeStartDate));
                }


                if (value.Category == null)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, CategoryIsNull));
                }

                if (value.Category.IsScorecard && (string.IsNullOrEmpty(value.CaseNumber) || string.IsNullOrWhiteSpace(value.CaseNumber)))
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, CaseNumberIsNull));
                }

                if (!value.Category.IsScorecard && !string.IsNullOrEmpty(value.CaseNumber) && !string.IsNullOrEmpty(value.CaseNumber))
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, CaseNumberIsNotNull));
                }

                TimeKeepEntry find = TimeKeepEntry.Read(value.ID.Value);
                if (find == null)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.NotFound, noEntries));
                }

                value.Update();
                return(Request.CreateResultResponse <TimeKeepEntry>(value));
            }
            catch (Exception ex)
            {
                return(Request.CreateCustomErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Example #3
0
 public virtual HttpResponseMessage Get(Guid id)
 {
     try
     {
         TimeKeepEntry entry = TimeKeepEntry.Read(id);
         if (!ValidateUser(RequestContext.Principal, entry))
         {
             return(Request.CreateCustomErrorResponse(HttpStatusCode.Forbidden, userNotAllowed));
         }
         if (entry == null)
         {
             return(Request.CreateCustomErrorResponse(HttpStatusCode.NotFound, noEntries));
         }
         return(Request.CreateResultResponse <TimeKeepEntry>(entry));
     }
     catch (Exception ex)
     {
         return(Request.CreateCustomErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }