Example #1
0
        public virtual ContentResult CreateDownload(CreateDownloadModel model)
        {
            var response = new CreateDownloadResponseModel(model.EmailAddress, true);

            var data = new CaptchaVerifyModel(model.CaptchaToken);

            if (!ValidateCaptchaToken(data))
            {
                response.Success = false;
                response.Message = "Please complete the captcha before continuing";
                return(Content(new JavaScriptSerializer().Serialize(response)));
            }



            try
            {
                var startTime = DateTime.Parse(model.StartTime);
                response.InPointHasError = false;
                var endTime = DateTime.Parse(model.EndTime);
                response.OutPointHasError = false;

                var apiResponse = _downloadService.CreateDownload(model.EventId, startTime, endTime, model.EmailAddress, model.AudioOnly);
                response.Success = apiResponse.Successful;
                response.Message = apiResponse.Message;
                if (apiResponse.Successful)
                {
                    response.Message += String.Format(" You have {0} downloads remaining. This will reset in {1} hours", apiResponse.DownloadsRemaining, apiResponse.ResetHours);
                }
                if (apiResponse.ResetMinutes > 0)
                {
                    response.Message += String.Format(" & {0} minutes", apiResponse.ResetMinutes);
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "An error has occurred.";
            }

            var json = new JavaScriptSerializer().Serialize(response);

            return(Content(json));
        }