public static VIDEO Add(String fileName, String fileExtention, String description, string videoTitle, int sourceType, decimal sourceId, string sourceStep, string injuryType, string bodyPart, string videoType, DateTime videoDate, DateTime incidentDate, Stream file, decimal plantId) { VIDEO ret = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { VIDEO video = new VIDEO(); //video.FILE_NAME = filename; video.DESCRIPTION = description; video.TITLE = videoTitle; video.SOURCE_TYPE = sourceType; video.SOURCE_ID = sourceId; video.SOURCE_STEP = sourceStep; if (plantId > 0) { PLANT plant = SQMModelMgr.LookupPlant(plantId); video.COMPANY_ID = (decimal)plant.COMPANY_ID; video.BUS_ORG_ID = (decimal)plant.BUS_ORG_ID; video.PLANT_ID = plantId; } else { video.COMPANY_ID = SessionManager.EffLocation.Company.COMPANY_ID; video.BUS_ORG_ID = SessionManager.UserContext.Person.BUS_ORG_ID; video.PLANT_ID = SessionManager.UserContext.Person.PLANT_ID; } video.VIDEO_PERSON = SessionManager.UserContext.Person.PERSON_ID; video.CREATE_DT = WebSiteCommon.CurrentUTCTime(); video.VIDEO_TYPE = videoType; // this is the injury/incident type. Default to 0 for Media & audit video.VIDEO_DT = videoDate; video.INCIDENT_DT = incidentDate; video.INJURY_TYPES = injuryType; video.BODY_PARTS = bodyPart; video.VIDEO_STATUS = ""; //video.FILE_NAME = fileName; video.FILE_SIZE = file.Length; entities.AddToVIDEO(video); entities.SaveChanges(); // use the video id, but have to save video video.FILE_NAME = video.VIDEO_ID.ToString() + fileExtention; entities.SaveChanges(); // this is the code for saving the file in the Azure cloud if (video != null) { // get the container from the settings table List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("MEDIA_UPLOAD", ""); string storageContainer = sets.Find(x => x.SETTING_CD == "STORAGE_CONTAINER").VALUE.ToString(); CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(storageContainer); CloudBlockBlob blockBlob = container.GetBlockBlobReference(video.VIDEO_ID.ToString() + fileExtention); blockBlob.UploadFromStream(file); } ret = video; } } catch (Exception e) { //SQMLogger.LogException(e); ret = null; } return(ret); }