public int AddNewImage(OrderezeTask.Image image) { int id = 0; try { using (SqlConnection connection = new SqlConnection(connectionString)) { try { SqlCommand cmd = new SqlCommand("INSERT INTO " + databaseImagesTable + " (Name, Description, ImagePath) VALUES (@Name, @Description, @ImagePath)"); //cmd.CommandType = CommandType.Text; cmd.Connection = connection; cmd.Parameters.AddWithValue("@Name", image.Name); cmd.Parameters.AddWithValue("@Description", image.Description); cmd.Parameters.AddWithValue("@ImagePath", "https://geoklar.blob.core.windows.net/images/" + image.Name); connection.Open(); id = cmd.ExecuteNonQuery(); } catch (Exception ex) { ex.ToString(); } } } catch { } return id; }
public int insertImageToDb(OrderezeTask.Image image) { using (SqlConnection conn = new SqlConnection(connstring)) { SqlCommand CmdSql = new SqlCommand("INSERT INTO [imagesTable] (Name, Description,imagepath) VALUES (@Name, @Description, @Imagepath);SELECT SCOPE_IDENTITY();", conn); conn.Open(); CmdSql.Parameters.AddWithValue("@Name", image.Name); CmdSql.Parameters.AddWithValue("@Description", image.Description); CmdSql.Parameters.AddWithValue("@Imagepath", image.ImagePath); object newimageid = CmdSql.ExecuteScalar(); conn.Close(); return int.Parse(newimageid.ToString()); } }
public string uploadFileToBlob(OrderezeTask.Image imageforupload) { var blobcontainer = blobGetContainerRef(blobClientConnect("StorageConnectionString"), "imagecontainer"); var blob = blobGetBlobRef(blobcontainer, Guid.NewGuid().ToString()+Path.GetExtension(imageforupload.ImagePath)); using (var fileStream = System.IO.File.OpenRead(imageforupload.ImagePath)) { blob.UploadFromStream(fileStream); } blob.Properties.ContentType = System.Web.MimeMapping.GetMimeMapping(imageforupload.ImagePath); blob.SetProperties(); return blob.Uri.ToString(); }