public ActionResult SubmitRequest(string requestId)
        {
            var actualRequestId = (String.IsNullOrWhiteSpace(requestId) ? this.Provider.CreateNewRequestId() : requestId);
            var model = new PortfolioCalculationRequestInputModel
                            {
                                RequestId = actualRequestId,
                            };

            return View("~/Views/PortfolioCalculationRequest/Submit.cshtml", model);
        }
        public virtual PortfolioCalculationRequestSubmitModel SubmitRequest(PortfolioCalculationRequestInputModel input)
        {
            Assert.Fail(() => (input != null), "The PortfolioCalculationRequestModel parameter is null");
            Assert.Fail(()=>(!String.IsNullOrWhiteSpace(input.RequestId)), "The RequestId property of the PortfolioCalculationRequestModel is null or whitespace");

            // save the request id
            var requestId = this.SaveInitialRequest(input);
            // save the file to S3
            var fileInfo = this.SavePortfolioFile(input);
            // save the user record to SimpleDB that represents the actual file
            var saveUserFileInfo = this.SaveUserFileRecord(requestId, fileInfo);

            var model = this.CreateSubmitModel(requestId, fileInfo, saveUserFileInfo);
            return model;
        }
 public ActionResult SubmitRequest(PortfolioCalculationRequestInputModel model)
 {
     try
     {
         this.ValidateNewRequest(model);
         model.Origin = this.GetOrigin();
         var submitModel = this.Provider.SubmitRequest(model);
         return View("~/Views/PortfolioCalculationRequest/ResponseOk.cshtml", submitModel);
     }
     catch (PortfolioCalculationRequestValidationException pexc)
     {
         this.Provider.LogRequestError(model.RequestId, pexc.Message);
         var exceptionModel = new PortfolioCalculationRequestExceptionModel
                                  {
                                      RequestId = model.RequestId,
                                      ValidationException = pexc
                                  };
         return View("~/Views/PortfolioCalculationRequest/RequestException.cshtml", exceptionModel);
     }
 }
        public void SubmitRequest_throws_if_input_RequestId_is_null()
        {
            // arrange
            var provider = new PortfolioCalculationRequestProvider();
            var input = new PortfolioCalculationRequestInputModel {RequestId = null};

            // act
            // assert
            Assert.Throws<Exception>(() => provider.SubmitRequest(input));
        }
 protected internal virtual string CalculatePortfolioFileSavePath(PortfolioCalculationRequestInputModel input)
 {
     // how do we determine where to save the file?
     var folder = this.GetS3PortfolioFolder(input);
     var fileName = this.GetS3PortfolioFileName(input);
     const string fmt = "{0}/{1}";
     var path = String.Format(fmt, folder, fileName);
     return path;
 }
 protected internal virtual PortfolioFileInfo SavePortfolioFile(PortfolioCalculationRequestInputModel input)
 {
     try
     {
         string clientFileName = input.ClientFileName;
         var path = this.CalculatePortfolioFileSavePath(input);
         var putInfo = this.S3Client.Save(input.FileStream, this.PortfolioBucketName, path);
         var portfolioFileInfo = this.ConvertToPortfolioFileInfo(putInfo);
         portfolioFileInfo.ClientFileName = clientFileName;
         return portfolioFileInfo;
     }
     catch (Exception exc)
     {
         this.LogRequestError(input.RequestId, exc.ToString());
         throw;
     }
 }
 protected internal virtual string SaveInitialRequest(PortfolioCalculationRequestInputModel model)
 {
     var request = this.Convert(model);
     var info = this.SimpleDbClient.SaveEntity<PortfolioCalculationRequest>(request);
     return info.PrimaryKey;
 }
 protected internal virtual string GetS3PortfolioFolder(PortfolioCalculationRequestInputModel input)
 {
     var now = SystemTime.Now().ToString("yyyy-MM-dd");
     return now;
 }
 protected internal virtual string GetS3PortfolioFileName(PortfolioCalculationRequestInputModel input)
 {
     // what do we know about the input file?
     return String.Format("{0}.{1}.port", input.RequestId, input.PortfolioFileType);
 }
        protected internal virtual PortfolioCalculationRequest Convert(PortfolioCalculationRequestInputModel model)
        {
            var request = new PortfolioCalculationRequest
                              {
                                  ClientIp = model.ClientIp,
                                  CreatedBy = model.CreatedBy,
                                  CreateTimestamp = model.CreateTimestamp,
                                  ModifiedBy = model.ModifiedBy,
                                  ModifyTimestamp = model.ModifyTimestamp,
                                  Origin = model.Origin,
                                  RequestTimestamp = model.RequestTimestamp,
                                  RequestId = model.RequestId,
                                  Status = PortfolioCalculationRequestStatus.New,

                              };

            return request;
        }
        protected internal virtual void ValidateNewRequest(PortfolioCalculationRequestInputModel model)
        {
            PortfolioCalculationRequestValidationException exc = null;

            if (model.PortfolioFile == null)
            {
                (exc ?? (exc = new PortfolioCalculationRequestValidationException()))
                    .Add(new Exception("You must provide a portfolio file."));
            }
            else
            {
                if (String.IsNullOrWhiteSpace(model.PortfolioFile.FileName))
                {
                    (exc ?? (exc = new PortfolioCalculationRequestValidationException()))
                        .Add(new Exception("You must provide a portfolio file."));
                }
                if (model.PortfolioFile.ContentLength > Config.MaximumPortfolioFileUploadSizeInBytes)
                {
                    (exc ?? (exc = new PortfolioCalculationRequestValidationException()))
                        .Add(new PortfolioFileSizeException(model.PortfolioFile.FileName, model.PortfolioFile.ContentLength, Config.MaximumPortfolioFileUploadSizeInBytes));
                }
            }

            if (exc != null)
            {
                throw exc;
            }
        }