public static Event ToEvent(this EventRead eventAzure, bool userIdAsPartitionKey) { var eventObj = new Event(); eventObj.Id = Guid.Parse(eventAzure.RowKey); if (userIdAsPartitionKey) { eventObj.Organizer = eventAzure.PartitionKey; } else { eventObj.Organizer = eventAzure.Organizer; } eventObj.AvailableSeats = eventAzure.AvailableSeats; eventObj.Description = eventAzure.Description; eventObj.EventDate = eventAzure.EventDate; eventObj.Name = eventAzure.Name; if (eventAzure.Status == "Draft") { eventObj.Status = EventStatus.Draft; } if (eventAzure.Status == "Live") { eventObj.Status = EventStatus.Live; } eventObj.TicketPrice = eventAzure.TicketPrice; eventObj.TotalSeats = eventAzure.TotalSeats; return eventObj; }
public bool CreateNewEvent(Event eventCreated) { bool result; var newEvent = eventCreated; newEvent.Id = Guid.NewGuid(); newEvent.Status = EventStatus.Draft; try { _dbContext.Events.Add(newEvent); _dbContext.SaveChanges(); result = true; // Update the read model _cloudContext.AddEvent(newEvent); } catch (Exception) { // Log the exception somewhere result = false; } return result; }
public void AddEvent(Event eventObj) { var eventToAdd = eventObj.ToEventRead(true); TableOperation addOperation = TableOperation.InsertOrReplace(eventToAdd); _tableMyEvents.Execute(addOperation); _cache.InvalidateCache(GenerateMyEventsKey(eventToAdd.PartitionKey)); }
public void DeleteEvent(Event eventObj) { string partitionKey = eventObj.Organizer; string rowKey = eventObj.Id.ToString(); var eventToDelete = new TicketRead() { PartitionKey = partitionKey, RowKey = rowKey, ETag = "*" }; TableOperation deleteOperation = TableOperation.Delete(eventToDelete); _tableEvents.Execute(deleteOperation); // Invalidate cache _cache.InvalidateCache(GenerateMyEventsKey(partitionKey)); }
public void UpdateEventSeats(Event eventObj) { string partitionKey = eventObj.EventDate.Year.ToString(); string rowKey = eventObj.Id.ToString(); var eventToUpdate = new DynamicTableEntity() { PartitionKey = partitionKey, RowKey = rowKey, ETag = "*" }; Dictionary<string, EntityProperty> newProperties = new Dictionary<string, EntityProperty>(); newProperties.Add("AvailableSeats", new EntityProperty(eventObj.AvailableSeats)); eventToUpdate.Properties = newProperties; TableOperation updateOperation = TableOperation.Merge(eventToUpdate); _tableEvents.Execute(updateOperation); // Invalidate cache _cache.InvalidateCache(GenerateLiveEventsKey(partitionKey)); }
public void MakeEventLive(Event eventObj) { string partitionKey = eventObj.Organizer; string rowKey = eventObj.Id.ToString(); var eventToUpdate = new DynamicTableEntity() { PartitionKey = partitionKey, RowKey = rowKey, ETag = "*" }; Dictionary<string, EntityProperty> newProperties = new Dictionary<string, EntityProperty>(); newProperties.Add("Status", new EntityProperty("Live")); eventToUpdate.Properties = newProperties; TableOperation updateOperation = TableOperation.Merge(eventToUpdate); _tableMyEvents.Execute(updateOperation); // Add the new live event to All Events table var eventToAdd = eventObj.ToEventRead(false); eventToAdd.Status = "Live"; TableOperation addOperation = TableOperation.InsertOrReplace(eventToAdd); _tableEvents.Execute(addOperation); // Invalidate cache _cache.InvalidateCache(GenerateLiveEventsKey(eventToAdd.PartitionKey)); }