Ejemplo n.º 1
0
        public HttpResponseMessage GetByUserId(GetUserEventsRequest request)
        {
            if (request == null)
            {
                return(ToolsBoxResponse.OK(new BasicResponseModel
                {
                    Message = "Request is empty",
                    Status = HttpStatusCode.BadRequest
                }));
            }

            DateTime start = DateTime.MinValue;

            if (!string.IsNullOrEmpty(request.StartDate) &&
                !DateTime.TryParse(request.StartDate, out start))
            {
                return(ToolsBoxResponse.OK(new BasicResponseModel
                {
                    Message = "Start date is not valid.",
                    Status = HttpStatusCode.BadRequest
                }));
            }

            DateTime end = string.IsNullOrEmpty(request.StartDate) ? DateTime.MaxValue : start;

            if (!string.IsNullOrEmpty(request.EndDate) &&
                !DateTime.TryParse(request.EndDate, out end))
            {
                return(ToolsBoxResponse.OK(new BasicResponseModel
                {
                    Message = "End date is not valid.",
                    Status = HttpStatusCode.BadRequest
                }));
            }

            request.Number = request.Number < 0 ? int.MaxValue : request.Number;

            var dbResponse = EventsHelper.GetEvents(request.CreatorId, start, end, request.Number);

            switch (dbResponse.Status)
            {
            case HttpStatusCode.OK:
                return(ToolsBoxResponse.OK(new GetEventsResponseModel
                {
                    Status = HttpStatusCode.OK,
                    Message = "Ok",
                    Events = dbResponse.Events
                }));

            default:
                return(ToolsBoxResponse.OK(new BasicResponseModel
                {
                    Message = dbResponse.Message,
                    Status = dbResponse.Status
                }));
            }
        }