コード例 #1
0
        public async Task <JsonResult> UploadFile()
        {
            var blobName = ""; // the name associated with the blob image

            try
            {
                var blobAdapter = new BlogStorageAdapter(); // adapter to the blog repository code
                foreach (string file in Request.Files)
                // this is populated by the html5 browser when the user selects a file and contains the file to upload
                {
                    var fileContent = Request.Files[file];
                    if (fileContent != null && fileContent.ContentLength > 0)
                    {
                        if (fileContent.ContentLength > 250000) // no images allowed over 250K
                        {
                            throw new Exception();
                        }
                        // get a stream
                        var stream = fileContent.InputStream;

                        var imageName = string.Format("mkt-{0}{1}",
                                                      Guid.NewGuid(),
                                                      Path.GetExtension(fileContent.FileName)); // provide a unique name for the blob image
                        var blockBlob = blobAdapter.GetBlockBlob(imageName);
                        blobName = blockBlob.Uri.ToString();
                        await blobAdapter.Add(blockBlob.Name, stream); // ask the blobAdapter to store the image
                    }
                }
            }
            catch (Exception e)
            {
                return(Json(e.Message));
            }
            return(Json(blobName));// return value to the ajax call
        }
コード例 #2
0
        protected override void Delete()
        {
            Entity = AnEvent.Attendees.Find(l => l.id == EventArgument);
            var adapter = new BlogStorageAdapter();

            adapter.Delete(Entity.AttendeeResource);


            AnEvent.Attendees.Remove(Entity);
            DbCommands.UpdateDbCommand.SetEntity(AnEvent); // save updated product
            Get();
            base.Delete();
        }
コード例 #3
0
        protected override void Delete()
        {
            // set product to delete Product
            Entity = TheEvent.Materials.Find(l => l.id == EventArgument);

            var adapter = new BlogStorageAdapter();

            adapter.Delete(Entity.Resource);


            TheEvent.Materials.Remove(Entity);
            DbCommands.UpdateDbCommand.SetEntity(TheEvent); // save updated product
            Get();
            base.Delete();
        }