Exemple #1
0
        static async Task Main(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder <EventContext>();

            optionsBuilder.UseCosmos(
                accountEndpoint: "https://*****:*****@"Assets\andrea-tosato\original.jpg");
                var    biAndreaTosato   = ImageStructure.PersonPictureOriginal(andreatosatoid, ".jpg");
                var    imageUriTosato   = await fileService.UploadImageAsync(biAndreaTosato.BlobContainerName, biAndreaTosato.FileName, Utility.ImageToByte(pathAndreaTosato));

                andreaTosato.SetPicture(imageUriTosato);
                andreaTosato.SetConfirmation(true);
                db.People.Add(andreaTosato);


                string marcozamanaid = Guid.NewGuid().ToString("N");
                Person marcoZamana   = new Person(marcozamanaid, "Marco", "Zamana");
                marcoZamana.SetMVPCode("5003347");
                string pathMarcoZamana = Path.Combine(currentPath, @"Assets\marco-zamana\original.jpg");
                var    biZamana        = ImageStructure.PersonPictureOriginal(marcozamanaid, ".jpg");
                var    imageUriZamana  = await fileService.UploadImageAsync(biZamana.BlobContainerName, biZamana.FileName, Utility.ImageToByte(pathMarcoZamana));

                marcoZamana.SetPicture(imageUriZamana);
                marcoZamana.SetConfirmation(true);
                db.People.Add(marcoZamana);

                var community = new Community("Cloudgen Verona");
                community.SetWebSite(new Uri("https://cloudgen.it"));
                string pathLogoCloudgen = Path.Combine(currentPath, @"Assets\cloudgen-verona\original.png");
                var    biCloudgen       = ImageStructure.CommunityPictureOriginal("cloudgen-verona", ".png");
                var    imageUriCloudgen = await fileService.UploadImageAsync(biCloudgen.BlobContainerName, biCloudgen.FileName, Utility.ImageToByte(pathLogoCloudgen));

                community.SetLogo(imageUriCloudgen);
                community.AddManager(andreaTosato);
                community.AddManager(marcoZamana);
                community.SetConfirmation(true);
                await db.Communities.AddAsync(community).ConfigureAwait(false);

                string eventid     = Guid.NewGuid().ToString("N");
                var    globalAzure = new Event(eventid, "Global Azure",
                                               new DateTime(2020, 04, 24, 9, 0, 0),
                                               new DateTime(2020, 04, 24, 18, 0, 0));
                globalAzure.AddCommunity(community.ToOwned());
                globalAzure.SetBuyTicket(new Uri("https://www.eventbrite.it/e/biglietti-global-azure-2020-88158844477"));
                string pathGlobalAzure = Path.Combine(currentPath, @"Assets\global-azure\original.png");
                var    biGlobalAzure   = ImageStructure.EventPictureOriginal(eventid, ".png");
                var    imageUriAzure   = await fileService.UploadImageAsync(biGlobalAzure.BlobContainerName, biGlobalAzure.FileName, Utility.ImageToByte(pathGlobalAzure));

                globalAzure.SetLogo(imageUriAzure);
                var cfp = new CallForSpeaker(new Uri("https://sessionize.com/global-azure-2020/"), new DateTime(2020, 01, 31), new DateTime(2020, 02, 28));
                globalAzure.SetCallForSpeaker(cfp);
                globalAzure.SetConfirmation(true);


                await db.Events.AddAsync(globalAzure).ConfigureAwait(false);

                await db.SaveChangesAsync();

                id = globalAzure.Id;
            }


            using (var db = new EventContext(optionsBuilder.Options))
            {
                var c = db.Database.GetCosmosClient();

                var e = await db.Events.FindAsync(id).ConfigureAwait(false);

                Console.WriteLine(JsonSerializer.Serialize(e).ToString());
            }
        }
Exemple #2
0
        public async Task <IActionResult> PostImage(
            [HttpTrigger(AuthorizationLevel.Anonymous, HttpVerbs.POST, Route = "UploadImage")] HttpRequestMessage req,
            ILogger log)
        {
            var provider = new MultipartMemoryStreamProvider();
            await req.Content.ReadAsMultipartAsync(provider);

            var file          = provider.Contents.First();
            var fileExtension = new FileInfo(file.Headers.ContentDisposition.FileName.Replace("\"", "")).Extension.ToLower();
            var fileData      = await file.ReadAsByteArrayAsync();

            var    querystring = req.RequestUri.ParseQueryString();
            string typeUpload  = querystring.Get("type");
            string id          = querystring.Get("id");

            if (string.IsNullOrEmpty(typeUpload) || string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("Id and UploadType must not be empty");
            }
            Uri             imageStorageUri = null;
            BlobInformation blobInformation;

            switch (typeUpload.ToUpper())
            {
            case "COMMUNITY":
                if (await communityService.ExistsAsync(id))
                {
                    blobInformation = ImageStructure.CommunityPictureOriginal(id, fileExtension);
                    imageStorageUri = await fileService.UploadImageAsync(blobInformation.BlobContainerName, blobInformation.FileName, fileData).ConfigureAwait(false);

                    await communityService.UpdateImageAsync(id, imageStorageUri).ConfigureAwait(false);
                }
                else
                {
                    throw new ArgumentException($"Community id: {id}, not exist");
                }
                break;

            case "EVENT":
                if (await eventService.ExistsAsync(id))
                {
                    blobInformation = ImageStructure.EventPictureOriginal(id, fileExtension);
                    imageStorageUri = await fileService.UploadImageAsync(blobInformation.BlobContainerName, blobInformation.FileName, fileData).ConfigureAwait(false);

                    await eventService.UpdateLogoAsync(id, imageStorageUri).ConfigureAwait(false);
                }
                else
                {
                    throw new ArgumentException($"Event id: {id}, not exist");
                }
                break;

            case "PERSON":
                if (await personService.ExistsAsync(id))
                {
                    blobInformation = ImageStructure.PersonPictureOriginal(id, fileExtension);
                    imageStorageUri = await fileService.UploadImageAsync(blobInformation.BlobContainerName, blobInformation.FileName, fileData);

                    await personService.UpdateImageAsync(id, imageStorageUri);
                }
                else
                {
                    throw new ArgumentException($"Person id: {id}, not exist");
                }
                break;
            }
            return(new OkObjectResult(new { ImageUrl = imageStorageUri }));
        }