Exemplo n.º 1
0
        /// <summary>
        /// Gets the list of time keep entries for a given a case number and time range
        /// </summary>
        /// <param name="user">The case number</param>
        /// <param name="range">The range</param>
        /// <returns>HttpResponseMessage</returns>
        public override HttpResponseMessage GetByCaseTotals(string casenumber, DateRange range)
        {
            try
            {
                if (casenumber == null || casenumber.Trim().Length == 0)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, CaseNumberIsNull2));
                }
                if (range == null)
                {
                    return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, rangeIsNull));
                }
                IEnumerable <TimeKeepEntry> entries = TimeKeepEntry.ReadByCase(casenumber, GetPrincipalUser(RequestContext.Principal), range);
                TimeSpan totalLabor    = TimeSpan.FromTicks(entries.Sum(c => c.LaborTS.Value.Ticks));
                TimeSpan unloggedLabor = TimeSpan.FromTicks(entries.Where(c => !c.IsLogged).Sum(c => c.LaborTS.Value.Ticks));

                CaseTotalsResponse response = new CaseTotalsResponse {
                    TotalLabor = totalLabor, TotalUnloggedLabor = unloggedLabor
                };

                return(Request.CreateResultResponse <CaseTotalsResponse>(response));
            }
            catch (Exception ex)
            {
                return(Request.CreateCustomErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Exemplo n.º 2
0
 public virtual HttpResponseMessage GetByCase(string casenumber, [FromBody] DateRange range)
 {
     try
     {
         if (casenumber == null || casenumber.Trim().Length == 0)
         {
             return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, CaseNumberIsNull2));
         }
         if (range == null)
         {
             return(Request.CreateCustomErrorResponse(HttpStatusCode.BadRequest, rangeIsNull));
         }
         return(Request.CreateResultResponse <IEnumerable <TimeKeepEntry> >(TimeKeepEntry.ReadByCase(casenumber, GetPrincipalUser(RequestContext.Principal), range)));
     }
     catch (Exception ex)
     {
         return(Request.CreateCustomErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }