public Guid Save(File file) { Guid retVal = default(Guid); IList<SqlParameter> sqlParams = new List<SqlParameter>(); sqlParams.Add(new SqlParameter("@FileName", file.Name)); //sqlParams.Add(new SqlParameter("@AlternateText", image.AlternateText)); sqlParams.Add(new SqlParameter("@File", file.Data)); //sqlParams.Add(new SqlParameter("@MediaType", image.ContentType)); //Not available/working in my code -DBD 12/31/2010 sqlParams.Add(new SqlParameter("@MediaType", file.MediaType)); SqlParameter outParm = new SqlParameter("@MediaId", SqlDbType.UniqueIdentifier); outParm.Direction = ParameterDirection.Output; sqlParams.Add(outParm); using (SqlCommand command = new SqlCommand("[dbo].[CreateMedia]") { CommandType = CommandType.StoredProcedure }) { command.Parameters.AddRange(sqlParams.ToArray()); try { this.ExecuteNonQuery(command); retVal = (Guid)command.Parameters["@MediaId"].Value; } catch (Exception exc) { //Elmah.ErrorSignal.FromCurrentContext().Raise(exc); throw new Exception("Error uploading image.", exc); } } return retVal; }
public Guid Save(File file, int projectVersionId) { Guid guid = default(Guid); using (TransactionScope ts = new TransactionScope()) { guid = this.Save(file); if (guid.Equals(default(Guid))) throw new NoNullAllowedException("File was not uploaded"); IList<SqlParameter> sqlParams = new List<SqlParameter>(); sqlParams.Add(new SqlParameter("@ProjectVersionId", projectVersionId)); sqlParams.Add(new SqlParameter("@MediaId", guid)); using (SqlCommand command = new SqlCommand("[dbo].[LinkProjectVersionMedia]") { CommandType = CommandType.StoredProcedure }) { command.Parameters.AddRange(sqlParams.ToArray()); try { this.ExecuteNonQuery(command); } catch (Exception exc) { //Elmah.ErrorSignal.FromCurrentContext().Raise(exc); throw new Exception("Error joining media to projectversion.", exc); } } ts.Complete(); } return guid; }