Ejemplo n.º 1
0
        public async Task<ActionResult> AddNew(TableInsertModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }


            string name = string.Empty;
            if (model.File != null)
            {
                var fileEnding = model.File.FileName.Split('.').Last();

                name = Guid.NewGuid().ToString() + "." + fileEnding;

                var blob = container.GetBlockBlobReference(name);

                await blob.UploadFromStreamAsync(model.File.InputStream);
            }

            var operation = TableOperation.Insert(new TableModel(model.AuthorKey, model.TitleKey) { Author = model.AuthorKey, Title = model.TitleKey, Description = model.Description, Type = model.Type, Location = model.Location, FileName = name });

            await table.ExecuteAsync(operation);

            return RedirectToAction("Gallery");
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> Edit(TableInsertModel model)
        {
            var operation = TableOperation.Retrieve<TableModel>(model.AuthorKey, model.TitleKey);

            var tableModel = (TableModel)table.Execute(operation).Result;

            string name = tableModel.FileName;
            if (model.File != null)
            {
                if (!string.IsNullOrEmpty(name))
                {
                    var oldBlob = container.GetBlockBlobReference(name);
                    oldBlob.Delete();
                }

                var fileEnding = model.File.FileName.Split('.').Last();

                name = Guid.NewGuid().ToString() + "." + fileEnding;

                var blob = container.GetBlockBlobReference(name);

                await blob.UploadFromStreamAsync(model.File.InputStream);
            }


            tableModel.Author = model.Author;
            tableModel.Title = model.Title;
            tableModel.Location = model.Location;
            tableModel.Type = model.Type;
            tableModel.Description = model.Description;
            tableModel.FileName = name;

            var replaceOperation = TableOperation.Replace(tableModel);

            table.Execute(replaceOperation);

            return RedirectToAction("Gallery");
        }
Ejemplo n.º 3
0
        public ActionResult Edit(string partitionKey, string rowKey)
        {
            var operation = TableOperation.Retrieve<TableModel>(partitionKey, rowKey);

            var tablemodel = (TableModel)table.Execute(operation).Result;

            var model = new TableInsertModel()
            {
                AuthorKey = tablemodel.PartitionKey,
                TitleKey = tablemodel.RowKey,
                Author = tablemodel.Author,
                Title = tablemodel.Title,
                Location = tablemodel.Location,
                Type = tablemodel.Type,
                Description = tablemodel.Description,
                FileName = tablemodel.FileName,
            };

            return View(model);
        }