public async Task UpdateAsync(EventViewModel eventVM) { var currentEvent = await db.Events.FindAsync(eventVM.Id).ConfigureAwait(false); if (!string.IsNullOrEmpty(eventVM.BuyTicket)) { currentEvent.SetBuyTicket(new Uri(eventVM.BuyTicket)); } currentEvent.SetConfirmation(eventVM.Confirmed); //TODO: Update date and name if (eventVM.CFP != null) { currentEvent.SetCallForSpeaker(new CallForSpeaker(new Uri(eventVM.CFP.Url), eventVM.CFP.StartDate, eventVM.CFP.EndDate)); } if (!string.IsNullOrEmpty(eventVM.CommunityName)) { Community community = await db.Communities.FindAsync(eventVM.CommunityName).ConfigureAwait(false); db.Entry(community).State = EntityState.Detached; if (community != null) { for (int i = 0; i < community.ManagerCollection.Count; i++) { var p = await db.People.FindAsync(community.ManagerCollection.ElementAt(i)).ConfigureAwait(false); community.AddManager(p); } currentEvent.AddCommunity(community.ToOwned()); } else { throw new ArgumentOutOfRangeException($"No community {eventVM.CommunityName} found"); } } db.Events.Update(currentEvent); await db.SaveChangesAsync().ConfigureAwait(false); }
public async Task <string> CreateAsync(CommunityViewModel communityVM) { Community domain = new Community(communityVM.Name); domain.SetConfirmation(false); domain.SetWebSite(new Uri(communityVM.WebSite)); foreach (var m in communityVM.Managers) { var foundManager = await db.People.FindAsync(m.Id).ConfigureAwait(false); if (foundManager == null) { throw new ArgumentOutOfRangeException($"No person find with id {m.Id}"); } else { domain.AddManager(foundManager.ToOwned()); } } db.Communities.Add(domain); await db.SaveChangesAsync().ConfigureAwait(false); return(domain.ShortName); }
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()); } }