//PHOTOS - INSERT public static int PhotosInsert(PhotosAdd model) { int id = 0;//000-0000-0000-0000 DataProvider.ExecuteNonQuery(GetConnection, "dbo.Photos_Insert" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@URL", model.URL); paramCollection.AddWithValue("@isPrimary", 0); paramCollection.AddWithValue("@userId", model.userId); SqlParameter p = new SqlParameter("@PhotoId", System.Data.SqlDbType.Int); //output parameter sending into proc to get value p.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(p); }, returnParameters : delegate(SqlParameterCollection param) { int.TryParse(param["@PhotoId"].Value.ToString(), out id); } ); return(id); }
public HttpResponseMessage UploadGalleryPhoto() { HttpResponseMessage result = null; HttpRequest httpRequest = HttpContext.Current.Request; TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(ConfigService.AwsAccessKeyId , ConfigService.AwsSecretAccessKey , Amazon.RegionEndpoint.USWest2)); if (httpRequest.Files.Count > 0) { foreach (string file in httpRequest.Files) { HttpPostedFile postedFile = httpRequest.Files[file]; string guid = Guid.NewGuid().ToString(); string remoteFilePath = ConfigService.RemoteFilePath + guid + "_" + postedFile.FileName; TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest { BucketName = ConfigService.BucketName, InputStream = postedFile.InputStream, Key = remoteFilePath, }; fileTransferUtility.Upload(fileTransferUtilityRequest); string paraRemoteFilePath = "/" + remoteFilePath; ItemResponse <string> response = new ItemResponse <string>(); PhotosAdd model = new PhotosAdd(); //model binding by hand. creating a new instance of the model w/ file uploads model.userId = UserService.GetCurrentUserId(); model.URL = paraRemoteFilePath; PhotosService.PhotosInsert(model); response.Item = remoteFilePath; return(Request.CreateResponse(HttpStatusCode.Created, response.Item)); } } else { result = Request.CreateResponse(HttpStatusCode.BadRequest); } return(result); }