// GET: Assets/Create public async Task <ActionResult> Create() { var model = new AddAssetViewModel() { Applications = await db.Applications.ToListAsync(), Asset = new Asset() }; return(View(model)); }
public async Task <ActionResult> Create([Bind(Include = "Asset")] AddAssetViewModel model) { if (ModelState.IsValid) { var selectedApplication = await db.Applications.FirstAsync(app => app.Id == model.Asset.Application.Id); model.Asset.Application = selectedApplication; selectedApplication.Assets.Add(model.Asset); db.Assets.Add(model.Asset); await db.SaveChangesAsync(); // download the selected file var client = await EnsureSharePointClientCreatedAsync(); using (var stream = await client.Files.GetById(model.Asset.RawUrl).ToFile().DownloadAsync()) { // and copy it to the destination storage account var storageAccount = CloudStorageAccount.Parse( @"DefaultEndpointsProtocol=https;AccountName=wchstorage;AccountKey=3eEeXTV0hn/sdYEyQQ5fMS6HMrLBZP6Fdm4EStxV+ySCWeUJLCYFddxQYTaDUZn+zZtdkud+JyRAu32kuYwpeA==;BlobEndpoint=https://wchstorage.blob.core.windows.net/;TableEndpoint=https://wchstorage.table.core.windows.net/;QueueEndpoint=https://wchstorage.queue.core.windows.net/;FileEndpoint=https://wchstorage.file.core.windows.net/"); var blobclient = storageAccount.CreateCloudBlobClient(); var container = blobclient.GetContainerReference("rawvideos"); var blockblob = container.GetBlockBlobReference(string.Format("{0}.mp4", model.Asset.RawUrl)); await blockblob.UploadFromStreamAsync(stream); } // queue a message for further processing ConnectionStringSettings connectionString = ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"]; CloudStorageAccount storageAccount2 = CloudStorageAccount.Parse(connectionString.ConnectionString); CloudQueueClient queueClient = storageAccount2.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference("videoqueue"); queue.CreateIfNotExists(); VideoInformation videoInformation = new VideoInformation(); videoInformation.Uri = new Uri(model.Asset.RawUrl + ".mp4"); videoInformation.Id = Guid.NewGuid(); CloudQueueMessage message = new CloudQueueMessage(JsonConvert.SerializeObject(videoInformation)); queue.AddMessage(message); return(RedirectToAction("Index")); } return(View(model)); }
// GET: Assets/Create public async Task <ActionResult> Create() { var client = await EnsureSharePointClientCreatedAsync(); var files = await GetFilesAsync(client); var model = new AddAssetViewModel() { Applications = await db.Applications.ToListAsync(), Asset = new Asset(), OneDriveFiles = files }; return(View(model)); }
public async Task <ActionResult> Create([Bind(Include = "Asset")] AddAssetViewModel model) { if (ModelState.IsValid) { var selectedApplication = await db.Applications.FirstAsync(app => app.Id == model.Asset.Application.Id); model.Asset.Application = selectedApplication; selectedApplication.Assets.Add(model.Asset); db.Assets.Add(model.Asset); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }
/// <summary> /// Insert Update Asset Log on Asset update /// </summary> /// <param name="aavm"></param> /// <param name="assetId"></param> /// <param name="userid"></param> /// <param name="username"></param> public void InsertAssetUpdateLog(AddAssetViewModel aavm, long assetId, long userid, string username) { //Create Update Asset Log string UpdateQueryLog = String.Format( @" INSERT INTO {0} (AssetName, ModelNo, AssetCategoryId, Manufacturer, ConfigurationInfo, CreatedDate, ActionType, UserId, Username) VALUES ('{1}', '{2}', {3}, '{4}', '{5}', '{6}', '{7}', {8}, '{9}') ", TableConstant.TBL_ASSET_ENTRY_LOG, aavm.AssetName, aavm.ModelNo, aavm.AssetCategoryId, aavm.Manufacturer, aavm.ConfigurationInfo, DateTime.Now, "Update", userid, username ); ado.ExecNonQuery(UpdateQueryLog); }
/// <summary> /// Update Asset by AssetId /// </summary> /// <param name="aavm">AddAssetViewModel</param> /// <param name="assetId">AssetId</param> public void UpdateAsset(AddAssetViewModel aavm, long assetId) { //Update Asset string UpdateQuery = String.Format( @" UPDATE {0} SET AssetCategoryId = {1}, Name = '{2}', AssetKey = '{3}', Model = '{4}', Manufacturer = '{5}', ConfigurationInfo = '{6}', Status = {7} WHERE Id = {8}", TableConstant.TBL_ASSET, aavm.AssetCategoryId, aavm.AssetName, aavm.AssetKey, aavm.ModelNo, aavm.Manufacturer, aavm.ConfigurationInfo, 1, assetId ); ado.ExecNonQuery(UpdateQuery); }
/// <summary> /// Adds the asset detail from a single form /// </summary> /// <param name="aavm">AddAssetViewModel</param> public void AddAsset(AddAssetViewModel aavm) { long assetCategoryId = Int64.Parse(aavm.AssetCategoryName); var assetName = aavm.AssetName; var modelNo = aavm.ModelNo; var manufacturer = aavm.Manufacturer; var configInfo = aavm.ConfigurationInfo; var status = aavm.Status; var obj = ado.ExecNonQuery( String.Format( @"INSERT INTO {0} (AssetCategoryId, Name, Model, Manufacturer, ConfigurationInfo, Status) OUTPUT Inserted.ID, Inserted.Name VALUES ({1}, '{2}', '{3}', '{4}', '{5}', {6})", TableConstant.TBL_ASSET, assetCategoryId, assetName, modelNo, manufacturer, configInfo, status )); }
public ActionResult AddAsset(AddAssetViewModel vm) { var Success = false; var Message = ""; var nameValidation = Asset.Validator.ValidateName(vm.Name); if (nameValidation != null) { ModelState.AddModelError("Name", nameValidation); } var valueValidation = Asset.Validator.ValidateValue(vm.Value); if (valueValidation != null) { ModelState.AddModelError("Value", valueValidation); } var modelValidation = Asset.Validator.ValidateAssetModel(vm.SelectedAssetModelId); if (modelValidation != null) { ModelState.AddModelError("AssetModel", modelValidation); } var serialValidation = Asset.Validator.ValidateSerialKey(vm.SerialNumber); if (serialValidation != null) { ModelState.AddModelError("SerialNumber", serialValidation); } if (vm.Properties != null) { for (var i = 0; i < vm.Properties.Count; i++) { var p = vm.Properties[i]; var property = db.AssetModelProperties.Find(p.PropertyId); var propertyValidation = Asset.Validator.ValidatePropertyValue(property, p.Value); if (propertyValidation != null) { ModelState.AddModelError($"Properties[{i}]", propertyValidation); } } } if (vm.SelectedRoomId < 0) { ModelState.AddModelError("SelectedRoomId", "Room is required"); } if (ModelState.IsValid) { try { var asset = new Asset { AssetModelId = vm.SelectedAssetModelId, Name = vm.Name, Value = vm.Value, SerialNumber = vm.SerialNumber, AssetProperties = new List <AssetProperty>(), Locations = new List <AssetLocation>(), }; if (vm.Properties != null) { foreach (var p in vm.Properties) { asset.AssetProperties.Add(new AssetProperty { Asset = asset, AssetModelPropertyId = p.PropertyId, Value = p.Value, }); } } var room = db.Rooms.Find(vm.SelectedRoomId); var location = new AssetLocation { Asset = asset, Room = room, TimeFrom = DateTime.Now, TimeTo = null, }; db.Assets.Add(asset); db.AssetLocations.Add(location); db.SaveChanges(); Success = true; Message = Asset.SAVE_SUCCESS; } catch (Exception e) { Message = Asset.SAVE_FAIL; } return(Json(new { Success, Message })); } vm.AssetModels = db.AssetModelDropdown(); vm.Rooms = db.RoomDropdown(); return(PartialView("_AddAsset", vm)); }