//store the Amazon file url into SQL database public int FileInsert(FileInsertRequest request) { //store the Amazon file url into SQL database int ID = 0; Guid CreatedBy = new Guid(userGuid); Guid ModifiedBy = CreatedBy; DataProvider.ExecuteNonQuery(GetConnection, "dbo.File_Insert" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@PersonID", request.PersonID); paramCollection.AddWithValue("@FileUrl", request.FileUrl); paramCollection.AddWithValue("@FileTitle", request.FileTitle); paramCollection.AddWithValue("@FileType", (int)request.FileType); paramCollection.AddWithValue("@CreatedBy", CreatedBy); SqlParameter p = new SqlParameter("@ID", System.Data.SqlDbType.Int); p.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(p); }, returnParameters : delegate(SqlParameterCollection paramCollection) { int.TryParse(paramCollection["@ID"].Value.ToString(), out ID); }); return(ID); }
//POST file to Amazon server public int UploadFile(AmazonAddRequest saveFile, string title) { bool retVal = false; int id = 0; //instantiate the request model for the SQL server FileInsertRequest payload = new FileInsertRequest(); // grab the current user id from the User Service int personId = UserService.UserSelect().PersonId; //hydrate the payload with information from the amazon object payload.PersonID = personId; payload.FileUrl = saveFile.keyName; payload.FileTitle = title.Replace("\"", ""); payload.CreatedBy = userGuid; payload.ModifiedBy = payload.CreatedBy; payload.FileType = saveFile.FileType; //upload the amazon object to the amazon server retVal = _uploadService.UploadFileFromFolder(saveFile); if (retVal) { //if successful (true), send the payload object to the SQL server. id = fms.FileInsert(payload); } ; return(id); }