public async void it_should_insert_the_event_into_the_store()
        {
            deleteEventStoreTable();

            var subject = new TableEventStore(CloudStorageAccount.DevelopmentStorageAccount, "test");

            var expected = new RaisedEvent(
                Guid.NewGuid(),
                new DummyEvent {Prop = "Property"},
                new DateTimeOffset(2013, 01, 17, 12, 06, 39, 967, TimeZoneInfo.Utc.BaseUtcOffset),
                "txid");

            var eventEntity = new EventEntity(expected);
            var insert = TableOperation.Insert(eventEntity);
            var inserted = Task.Factory.FromAsync<TableOperation, TableResult>(subject.EventStoreTable.BeginExecute,
                                                                               subject.EventStoreTable.EndExecute, insert, null);
            await inserted;

            var actual = storedEventEntity(expected);

            actual.ShouldNotBeNull();
            actual.Event.ShouldEqual(JsonEvent.ConvertToJson(expected));
            actual.RaisedTimestamp.ShouldEqual(expected.RaisedTimestamp);
            actual.TransactionId.ShouldEqual(expected.TransactionId);
        }
Exemplo n.º 2
0
        public static void InsertEventEntities(this Partition partition, params string[] ids)
        {
            for (int i = 0; i < ids.Length; i++)
            {
                var e = new EventEntity
                {
                    PartitionKey = partition.PartitionKey,
                    RowKey = (i+1).FormatEventRowKey()
                };

                partition.Table.Execute(TableOperation.Insert(e));
            }
        }
Exemplo n.º 3
0
 public EventEntity SearchTitle(EventEntity evnt)
 {
     return(hr.Get(evnt));
 }
        public string GetEditionListUrl(UrlHelper urlHelper, EventEntity @event, string fragment = null)
        {
            var url = urlHelper.AbsoluteAction("Index", "Edition", new { eventId = @event.EventId, name = @event.MasterName.ToUrlString() });

            return(url + fragment);
        }
Exemplo n.º 5
0
 public string GetSubject(EventEntity @event, NotificationType notificationType)
 {
     return(_emailSubjectStart + GetTitle(@event, notificationType, false));
 }
Exemplo n.º 6
0
		static EventData ToEventData(IEvent @event)
		{
			var id = Guid.NewGuid().ToString("D");

			var properties = new EventEntity
			{
				Id = id,
				Type = @event.GetType().FullName,
				Data = JsonConvert.SerializeObject(@event, SerializerSettings)
			};

			return new EventData(EventId.From(id), EventProperties.From(properties));
		}
Exemplo n.º 7
0
        static IEvent DeserializeEvent(EventEntity eventEntity)
        {
            var eventType = Type.GetType(TypeNameToQuallifiedName(eventEntity.Type), true);

            return((IEvent)JsonConvert.DeserializeObject(eventEntity.Data, eventType, SerializerSettings));
        }
        private async Task <ExistingStartMessageContext> ProcessStartMessageAsync(
            MessageChangeEvent change,
            EventEntity eventEntity,
            IComponent rootComponent,
            IComponent component,
            ExistingStartMessageContext existingStartMessageContext)
        {
            _logger.LogInformation("Applying change to component tree.");
            component.Status = change.AffectedComponentStatus;

            // This change may affect a component that we do not display on the status page.
            // Find the deepester ancestor of the component that is directly affected.
            _logger.LogInformation("Determining if change affects visible component tree.");
            var lowestVisibleComponent = rootComponent.GetDeepestVisibleAncestorOfSubComponent(component);

            if (lowestVisibleComponent == null || lowestVisibleComponent.Status == ComponentStatus.Up)
            {
                // The change does not bubble up to a component that we display on the status page.
                // Therefore, we shouldn't post a message about it.
                _logger.LogInformation("Change does not affect visible component tree. Will not post or edit any messages.");
                return(existingStartMessageContext);
            }

            // The change bubbles up to a component that we display on the status page.
            // We must post or update a message about it.
            if (existingStartMessageContext != null)
            {
                // There is an existing message we need to update.
                _logger.LogInformation("Found existing message, will edit it with information from new change.");
                // We must expand the scope of the existing message to include the component affected by this change.
                // In other words, if the message claims V2 Restore is down and V3 Restore is now down as well, we need to update the message to say Restore is down.
                var leastCommonAncestorPath = ComponentUtility.GetLeastCommonAncestorPath(existingStartMessageContext.AffectedComponent, lowestVisibleComponent);
                _logger.LogInformation("Least common ancestor component of existing message and this change is {LeastCommonAncestorPath}.", leastCommonAncestorPath);
                var leastCommonAncestor = rootComponent.GetByPath(leastCommonAncestorPath);
                if (leastCommonAncestor == null)
                {
                    // If the two components don't have a common ancestor, then they must not be a part of the same component tree.
                    // This should not be possible because it is asserted earlier that both these components are subcomponents of the root component.
                    throw new ArgumentException("Least common ancestor component of existing message and this change does not exist!", nameof(change));
                }

                if (leastCommonAncestor.Status == ComponentStatus.Up)
                {
                    // The least common ancestor of the component affected by the change and the component referred to by the existing message is unaffected!
                    // This should not be possible because the ancestor of any visible component should be visible (in other words, changes to visible components should always bubble up).
                    throw new ArgumentException("Least common ancestor of two visible components is unaffected!");
                }

                await _factory.UpdateMessageAsync(eventEntity, existingStartMessageContext.Timestamp, MessageType.Start, leastCommonAncestor);

                return(new ExistingStartMessageContext(existingStartMessageContext.Timestamp, leastCommonAncestor, leastCommonAncestor.Status));
            }
            else
            {
                // There is not an existing message we need to update.
                _logger.LogInformation("No existing message found. Creating new start message for change.");
                await _factory.CreateMessageAsync(eventEntity, change.Timestamp, change.Type, lowestVisibleComponent);

                return(new ExistingStartMessageContext(change.Timestamp, lowestVisibleComponent, lowestVisibleComponent.Status));
            }
        }
Exemplo n.º 9
0
 public EventPriceDto ConvertEntityToPriceDto(EventEntity entity)
 {
     return(new(entity.Id, entity.Date, entity.Name, entity.EventType, entity.Venue,
                entity.Capacity == 0 ? 0 : (int)(entity.Sold * 100.0 / entity.Capacity),
                PriceCalculator.CalculateForEvent(entity)));
 }
        public Task Handle(DeleteStatusEventManualChangeEntity entity)
        {
            var eventRowKey = EventEntity.GetRowKey(entity.EventAffectedComponentPath, entity.EventStartTime);

            return(_table.DeleteAsync(EventEntity.DefaultPartitionKey, eventRowKey));
        }
Exemplo n.º 11
0
 public EventTemplateData(EventEntity se)
 {
     this.se  = se;
     dataDict = JSON.Instance.Parse(se.data) as IDictionary <string, object>;
 }
Exemplo n.º 12
0
        public void AddEventSourcing(Message command, string actionName, object data)
        {
            var @event = EventEntity.GetEvent(actionName, command, "Marcos", data);

            _eventSourcingContext.SaveEvent(@event);
        }
Exemplo n.º 13
0
        public void AddEventSourcing(Message command, string actionName, Message lastCommand = null)
        {
            var @event = EventEntity.GetEvent(actionName, command, "Marcos", lastCommand);

            _eventSourcingContext.SaveEvent(@event);
        }
Exemplo n.º 14
0
        public async Task <Event> GetByIdAsync(Guid id)
        {
            EventEntity eventEntity = await _eventRepository.GetByIdAsync(id);

            return(Mapper.Map <EventEntity, Event>(eventEntity));
        }
        /// <summary>
        /// Create event details adaptive to be shown in compose box.
        /// </summary>
        /// <param name="eventDetails">Event details.</param>
        /// <param name="localizer">The localizer for localizing content</param>
        /// <param name="applicationBasePath">Application base URL.</param>
        /// <returns>An adaptive card with event details.</returns>
        private static AdaptiveCard GetEventDetailsAdaptiveCard(EventEntity eventDetails, IStringLocalizer <Strings> localizer, string applicationBasePath)
        {
            var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Height = AdaptiveHeight.Auto,
                                Width  = AdaptiveColumnWidth.Auto,
                                Items  = !string.IsNullOrEmpty(eventDetails.Photo) ? new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url = new Uri(eventDetails.Photo),
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                        PixelHeight         = 50,
                                        PixelWidth          = 50,
                                    },
                                }
                                :
                                new List <AdaptiveElement>(),
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = eventDetails.Name,
                                        Size   = AdaptiveTextSize.Large,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Text    = eventDetails.CategoryName,
                                        Wrap    = true,
                                        Size    = AdaptiveTextSize.Default,
                                        Weight  = AdaptiveTextWeight.Bolder,
                                        Color   = AdaptiveTextColor.Attention,
                                        Spacing = AdaptiveSpacing.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = $"**{localizer.GetString("DateAndTimeLabel")}:** ",
                                        Wrap = true,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = string.Format(CultureInfo.CurrentCulture, "{0} {1}-{2}", "{{DATE(" + eventDetails.StartDate.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture) + ")}}", "{{TIME(" + eventDetails.StartTime.Value.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}", "{{TIME(" + eventDetails.EndTime.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}"),
                                        Wrap = true,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing   = AdaptiveSpacing.None,
                        IsVisible = eventDetails.Type == (int)EventType.InPerson,
                        Columns   = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("Venue")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventDetails.Venue,
                                        Wrap = true,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.None,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("DescriptionLabelCard")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventDetails.Description,
                                        Wrap = true,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.ExtraLarge,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        IsVisible           = eventDetails.Audience == (int)EventAudience.Private,
                                        Url                 = new Uri($"{applicationBasePath}/images/Private.png"),
                                        PixelWidth          = 84,
                                        PixelHeight         = 32,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                    },
                                },
                            },
                        },
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("RegisterButton"),
                        Data  = new AdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type = "task/fetch",
                                Text = localizer.GetString("RegisterButton"),
                            },
                            Command = BotCommands.RegisterForEvent,
                            EventId = eventDetails.EventId,
                            TeamId  = eventDetails.TeamId,
                        },
                    },
                },
            };

            return(card);
        }
Exemplo n.º 16
0
 public bool Edit(EventEntity evnt)
 {
     return(hr.Update(evnt));
 }
        static void AssertEventEntity(int version, EventEntity actual)
        {
            var expected = new
            {
                RowKey = version.FormatEventRowKey(),
                Properties = EventProperties.From(new Dictionary<string, EntityProperty>
                {
                    {"Type", new EntityProperty("StreamChanged")},
                    {"Data", new EntityProperty("{}")},
                }),
                Version = version,
            };

            actual.ShouldMatch(expected.ToExpectedObject());
        }
        /// <summary>
        /// Get adaptive card attachment for sending event updation card to attendees.
        /// </summary>
        /// <param name="localizer">String localizer for localizing user facing text.</param>
        /// <param name="eventEntity">Event details which is cancelled.</param>
        /// <param name="applicationManifestId">The unique manifest ID for application</param>
        /// <returns>An adaptive card attachment.</returns>
        public static Attachment GetEventUpdateCard(IStringLocalizer <Strings> localizer, EventEntity eventEntity, string applicationManifestId)
        {
            eventEntity = eventEntity ?? throw new ArgumentNullException(nameof(eventEntity), "Event details cannot be null");

            AdaptiveCard autoRegisteredCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("EventUpdatedCardTitle")}**",
                                        Size   = AdaptiveTextSize.Large,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Height = AdaptiveHeight.Auto,
                                Width  = AdaptiveColumnWidth.Auto,
                                Items  = !string.IsNullOrEmpty(eventEntity.Photo) ? new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url = new Uri(eventEntity.Photo),
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                        PixelHeight         = 45,
                                        PixelWidth          = 45,
                                    },
                                }
                                :
                                new List <AdaptiveElement>(),
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = eventEntity.Name,
                                        Size   = AdaptiveTextSize.Default,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Text    = eventEntity.CategoryName,
                                        Wrap    = true,
                                        Size    = AdaptiveTextSize.Small,
                                        Weight  = AdaptiveTextWeight.Bolder,
                                        Color   = AdaptiveTextColor.Warning,
                                        Spacing = AdaptiveSpacing.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Medium,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("DateAndTimeLabel")}:**",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = string.Format(CultureInfo.CurrentCulture, "{0} {1}-{2}", "{{DATE(" + eventEntity.StartDate.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture) + ", SHORT)}}", "{{TIME(" + eventEntity.StartTime.Value.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}", "{{TIME(" + eventEntity.EndTime.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}"),
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = eventEntity.Type != (int)EventType.InPerson ? new List <AdaptiveColumn>() : new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("Venue")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.Venue,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("Description")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.Description,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.ExtraLarge,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveActionSet
                                    {
                                        Actions = new List <AdaptiveAction>
                                        {
                                            new AdaptiveOpenUrlAction
                                            {
                                                Url   = new Uri($"https://teams.microsoft.com/l/entity/{applicationManifestId}/my-events"),
                                                Title = $"{localizer.GetString("ReminderCardRegisteredEventButton")}",
                                            },
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = autoRegisteredCard,
            });
        }
Exemplo n.º 19
0
 /// <summary>
 ///  创建事件并发送给事件指定的uid.
 /// </summary>
 /// <param name="to">0 to all follow,1 to self,2 to all(不创建索引)</param>
 /// <param name="entity">事件实体</param>
 public static int CreateEvent(EventEntity entity)
 {
     return(EventData.CreateEvent(entity));
 }
Exemplo n.º 20
0
 private static IDomainEvent <TAggregateId> ToEvent <TAggregateId>(EventEntity e) where TAggregateId : IAggregateId
 {
     return((IDomainEvent <TAggregateId>)JsonConvert.DeserializeObject(e.Data, Type.GetType(e.Type), JsonSerializerSettings));
 }
Exemplo n.º 21
0
 private Event GetEvent(EventEntity entity)
 {
     return(messageSerializer.Deserialize <Event>(entity.Payload));
 }
Exemplo n.º 22
0
        public List <EventEntity> FetchAllEvents(DataAccess dataAccess)
        {
            List <EventEntity> events = new List <EventEntity>();

            EventEntity eventEntity = new EventEntity();

            try {
                command = new SqlCommand(FECTH_ALL_EVENTS, dataAccess.GetConnection());
                reader  = command.ExecuteReader();

                while (reader.Read())
                {
                    int eventId = reader.GetInt32(reader.GetOrdinal("id"));

                    if (eventEntity.Id != eventId)
                    {
                        eventEntity            = new EventEntity();
                        eventEntity.Id         = eventId;
                        eventEntity.Topic      = reader.GetString(reader.GetOrdinal("topic"));
                        eventEntity.Host       = reader.GetString(reader.GetOrdinal("host"));
                        eventEntity.FromDate   = reader.GetDateTime(reader.GetOrdinal("event_startdate"));
                        eventEntity.ToDate     = reader.GetDateTime(reader.GetOrdinal("event_enddate"));
                        eventEntity.IsCanceled = reader.GetBoolean(reader.GetOrdinal("isCanceled"));

                        try {
                            DepartmentEntity departmentEntity = new DepartmentEntity();
                            departmentEntity.Id   = reader.GetInt32(reader.GetOrdinal("department_id"));
                            departmentEntity.Name = reader.GetString(reader.GetOrdinal("name"));

                            eventEntity.DepartmentEntity = departmentEntity;

                            RoomEntity re = new RoomEntity();
                            re.Id               = reader.GetInt32(reader.GetOrdinal("room_id"));
                            re.Identifier       = reader.GetString(reader.GetOrdinal("identifier"));
                            re.DepartmentEntity = departmentEntity;
                            eventEntity.Rooms.Add(re);
                        } catch (SqlNullValueException exc) {
                            // We need to ignore it, because a given event may be created without rooms and department.
                        }
                        events.Add(eventEntity);
                    }
                    else
                    {
                        try {
                            RoomEntity roomEntity = new RoomEntity();
                            roomEntity.Id         = reader.GetInt32(reader.GetOrdinal("room_id"));
                            roomEntity.Identifier = reader.GetString(reader.GetOrdinal("identifier"));

                            eventEntity.Rooms.Add(roomEntity);
                        } catch (SqlNullValueException exc) {
                            // We need to ignore it, because a given event may be created without rooms and department.
                        }
                    }
                }
            } catch (SqlException exc) {
            } finally {
                reader.Close();
            }
            eventsCount = events.Count;
            return(events);
        }
Exemplo n.º 23
0
        public ServiceMessage Create(BetCreateDTO betCreateDTO)
        {
            string message = "";
            bool   success = true;

            string   sportName      = betCreateDTO.SportName;
            string   tournamentName = betCreateDTO.TournamentName;
            DateTime dateOfEvent    = betCreateDTO.DateOfEvent;
            List <ParticipantBaseDTO> participants = betCreateDTO.EventParticipants;
            string  coefficientDescription         = betCreateDTO.CoefficientDescription;
            decimal sum = betCreateDTO.Sum;
            string  clientPhoneNumber    = betCreateDTO.ClientPhoneNumber;
            string  bookmakerPhoneNumber = betCreateDTO.BookmakerPhoneNumber;

            if (success = ValidateBase(betCreateDTO, ref message) && Validate(betCreateDTO, ref message))
            {
                try
                {
                    IEnumerable <ParticipantEntity> participantEntities = participants
                                                                          .Select(p => unitOfWork.Participants.Get(p.Name, p.SportName, p.CountryName));

                    EventEntity eventEntity = unitOfWork
                                              .Events
                                              .Get(sportName, tournamentName, dateOfEvent, participantEntities);

                    CoefficientEntity coefficientEntity = unitOfWork
                                                          .Coefficients
                                                          .Get(eventEntity.Id, coefficientDescription);

                    if (coefficientEntity != null)
                    {
                        bool exists = unitOfWork.Bets.Exists(coefficientEntity.Id, clientPhoneNumber);
                        if (!exists)
                        {
                            ClientEntity clientEntity = unitOfWork
                                                        .Clients
                                                        .Get(clientPhoneNumber);

                            BookmakerEntity bookmakerEntity = unitOfWork
                                                              .Bookmakers
                                                              .Get(bookmakerPhoneNumber);

                            BetEntity betEntity = new BetEntity
                            {
                                ClientId         = clientEntity.Id,
                                BookmakerId      = bookmakerEntity.Id,
                                CoefficientId    = coefficientEntity.Id,
                                RegistrationDate = DateTime.Now,
                                Sum = sum
                            };

                            unitOfWork.Bets.Add(betEntity);
                            unitOfWork.Commit();

                            message = "Created new bet";
                        }
                        else
                        {
                            message = "Such bet already exists";
                            success = false;
                        }
                    }
                    else
                    {
                        message = "Such coefficient was not found";
                        success = false;
                    }
                }
                catch (Exception ex)
                {
                    message = ExceptionMessageBuilder.BuildMessage(ex);
                    success = false;
                }
            }

            return(new ServiceMessage(message, success));
        }
Exemplo n.º 24
0
        static EventWorkflowHelperData()
        {
            eventEntity = new EventEntity
            {
                EventId    = "ad4b2b43-1cb5-408d-ab8a-17e28edac2baz-1234-2345",
                TeamId     = "ad4b2b43-1cb5-408d-ab8a-17e28edac2baz-1234",
                Audience   = 3,
                CategoryId = "088ddf0d-4deb-4e95-b1f3-907fc4511b02",
                AutoRegisteredAttendees = "",
                CategoryName            = "Test_Category",
                CreatedBy                   = "Jack",
                CreatedOn                   = new DateTime(2020, 09, 24),
                Description                 = "Teams Event",
                EndDate                     = new DateTime(2020, 09, 25),
                EndTime                     = new DateTime(2020, 09, 25),
                ETag                        = "",
                GraphEventId                = "088ddf0d-4deb-4e95-b1f3-907fc4511b02g",
                IsAutoRegister              = false,
                IsRegistrationClosed        = false,
                IsRemoved                   = false,
                MandatoryAttendees          = "",
                MaximumNumberOfParticipants = 10,
                MeetingLink                 = "",
                Name                        = "Mandaotory Training Event",
                NumberOfOccurrences         = 1,
                OptionalAttendees           = "",
                Photo                       = "https://testurl/img.png",
                StartDate                   = new DateTime(2020, 09, 25),
                StartTime                   = new DateTime(2020, 09, 25),
                UpdatedBy                   = "Jack",
                Venue                       = "",
                SelectedUserOrGroupListJSON = "",
                RegisteredAttendeesCount    = 0,
                Type                        = 0,
                RegisteredAttendees         = ""
            };

            validEventEntity = new EventEntity
            {
                EventId    = "ad4b2b43-1cb5-408d-ab8a-17e28edac2baz-1234-2345",
                TeamId     = "ad4b2b43-1cb5-408d-ab8a-17e28edac2baz-1234",
                Audience   = 1,
                CategoryId = "088ddf0d-4deb-4e95-b1f3-907fc4511b02",
                AutoRegisteredAttendees = "",
                CategoryName            = "Test_Category",
                CreatedBy                   = "Jack",
                CreatedOn                   = DateTime.UtcNow,
                Description                 = "Teams Event",
                EndDate                     = DateTime.UtcNow.AddDays(4).Date,
                EndTime                     = DateTime.UtcNow.AddDays(4).Date,
                ETag                        = "",
                GraphEventId                = "088ddf0d-4deb-4e95-b1f3-907fc4511b02g",
                IsAutoRegister              = false,
                IsRegistrationClosed        = false,
                IsRemoved                   = false,
                MandatoryAttendees          = "",
                MaximumNumberOfParticipants = 10,
                MeetingLink                 = "",
                Name                        = "Mandaotory Training Event",
                NumberOfOccurrences         = 1,
                OptionalAttendees           = "",
                Photo                       = "https://www.testurl.com/img.png",
                StartDate                   = DateTime.UtcNow.AddDays(2).Date,
                StartTime                   = DateTime.UtcNow.AddDays(2).Date,
                UpdatedBy                   = "Jack",
                Venue                       = "",
                SelectedUserOrGroupListJSON = "",
                RegisteredAttendeesCount    = 0,
                Type                        = 2,
                RegisteredAttendees         = ""
            };

            eventEntities = new List <EventEntity>()
            {
                new EventEntity
                {
                    EventId      = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-888",
                    CategoryId   = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba",
                    CategoryName = ""
                },
                new EventEntity
                {
                    EventId      = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999",
                    CategoryId   = "ad4b2b43-1cb5-408d-ab8a-17e28edac3ba",
                    CategoryName = ""
                }
            };

            category = new Category
            {
                CategoryId  = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba",
                Name        = "Test_Category_1",
                Description = "Description",
                CreatedBy   = "ad4b2b43-1cb5-408d-ab8a-17e28edacabc",
                CreatedOn   = DateTime.UtcNow,
                UpdatedOn   = DateTime.UtcNow,
            };

            categoryList = new List <Category>
            {
                new Category
                {
                    CategoryId  = "ad4b2b43-1cb5-408d-ab8a-17e28edac1ba",
                    Name        = "Test_Category_1",
                    Description = "Description",
                    CreatedBy   = "ad4b2b43-1cb5-408d-ab8a-17e28edacabc",
                    CreatedOn   = DateTime.UtcNow,
                    UpdatedOn   = DateTime.UtcNow,
                    IsInUse     = false,
                },
                new Category
                {
                    CategoryId  = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba",
                    Name        = "Test_Category_1",
                    Description = "Description",
                    CreatedBy   = "ad4b2b43-1cb5-408d-ab8a-17e28edacabc",
                    CreatedOn   = DateTime.UtcNow,
                    UpdatedOn   = DateTime.UtcNow,
                    IsInUse     = false,
                },
                new Category
                {
                    CategoryId  = "ad4b2b43-1cb5-408d-ab8a-17e28edac3ba",
                    Name        = "Test_Category_1",
                    Description = "Description",
                    CreatedBy   = "ad4b2b43-1cb5-408d-ab8a-17e28edacabc",
                    CreatedOn   = DateTime.UtcNow,
                    UpdatedOn   = DateTime.UtcNow,
                    IsInUse     = false,
                }
            };

            teamEvent = new Event
            {
                Subject = "Teams Event",
                Body    = new ItemBody
                {
                    ContentType = BodyType.Html,
                    Content     = eventEntity.Type == (int)EventType.LiveEvent ?
                                  $"{eventEntity.Description}<br/><br/><a href='{eventEntity.MeetingLink}'>{eventEntity.MeetingLink}</a>" :
                                  eventEntity.Description,
                },
                Attendees        = new List <Attendee>(),
                OnlineMeetingUrl = eventEntity.Type == (int)EventType.LiveEvent ? eventEntity.MeetingLink : null,
                IsReminderOn     = true,
                Location         = eventEntity.Type == (int)EventType.InPerson ? new Location
                {
                    Address = new PhysicalAddress {
                        Street = eventEntity.Venue
                    },
                }
                    : null,
                AllowNewTimeProposals = false,
                IsOnlineMeeting       = true,
                OnlineMeetingProvider = OnlineMeetingProviderType.TeamsForBusiness,
                Id = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-rrtyy"
            };

            lndTeam = new LnDTeam
            {
                ETag         = "",
                PartitionKey = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999",
                TeamId       = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-000",
                RowKey       = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-000"
            };

            graphUser = new Graph.User
            {
                DisplayName       = "Jack",
                UserPrincipalName = "Jack",
                Id   = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-001",
                Mail = "*****@*****.**"
            };

            graphUsers = new List <Graph.User>()
            {
                new Graph.User
                {
                    DisplayName       = "Jack",
                    UserPrincipalName = "Jack",
                    Id   = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-001",
                    Mail = "*****@*****.**"
                },
                new Graph.User
                {
                    DisplayName       = "Jack",
                    UserPrincipalName = "Jack",
                    Id   = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-002",
                    Mail = "*****@*****.**"
                },
                new Graph.User
                {
                    DisplayName       = "Jack",
                    UserPrincipalName = "Jack",
                    Id   = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-003",
                    Mail = "*****@*****.**"
                }
            };

            graphGroups = new List <Graph.Group>()
            {
                new Graph.Group
                {
                    DisplayName = "Jack",
                    Id          = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-001",
                    Mail        = "*****@*****.**"
                },
                new Graph.Group
                {
                    DisplayName = "Jack",
                    Id          = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-002",
                    Mail        = "*****@*****.**"
                },
                new Graph.Group
                {
                    DisplayName = "Jack",
                    Id          = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-003",
                    Mail        = "*****@*****.**"
                }
            };

            graphGroupDirectoryObject = new List <Graph.DirectoryObject>()
            {
                new Graph.DirectoryObject
                {
                    Id = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-001"
                },
                new Graph.DirectoryObject
                {
                    Id = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-002"
                },
                new Graph.DirectoryObject
                {
                    Id = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-003"
                }
            };

            fileInfo = new FormFile(new MemoryStream(), 1, 1, "sample.jpeg", "sample.jpeg");

            teamsChannelAccount = new List <TeamsChannelAccount>()
            {
                new TeamsChannelAccount
                {
                    GivenName         = "sam",
                    UserPrincipalName = "s"
                },
                new TeamsChannelAccount
                {
                    GivenName         = "jack",
                    UserPrincipalName = "j"
                }
            };

            teamEvent = new Event
            {
                Subject = "Teams Event",
                Body    = new ItemBody
                {
                    ContentType = BodyType.Html,
                    Content     = eventEntity.Type == (int)EventType.LiveEvent ?
                                  $"{eventEntity.Description}<br/><br/><a href='{eventEntity.MeetingLink}'>{eventEntity.MeetingLink}</a>" :
                                  eventEntity.Description,
                },
                Attendees        = new List <Attendee>(),
                OnlineMeetingUrl = eventEntity.Type == (int)EventType.LiveEvent ? eventEntity.MeetingLink : null,
                IsReminderOn     = true,
                Location         = eventEntity.Type == (int)EventType.InPerson ? new Location
                {
                    Address = new PhysicalAddress {
                        Street = eventEntity.Venue
                    },
                }
                    : null,
                AllowNewTimeProposals = false,
                IsOnlineMeeting       = true,
                OnlineMeetingProvider = OnlineMeetingProviderType.TeamsForBusiness,
                Id = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-rrtyy"
            };

            lndTeam = new LnDTeam
            {
                ETag         = "",
                PartitionKey = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999",
                TeamId       = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-000",
                RowKey       = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-000"
            };

            graphUser = new Graph.User
            {
                DisplayName       = "Jack",
                UserPrincipalName = "Jack",
                Id   = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-001",
                Mail = "*****@*****.**"
            };

            graphUsers = new List <Graph.User>()
            {
                new Graph.User
                {
                    DisplayName       = "Jack",
                    UserPrincipalName = "Jack",
                    Id   = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-001",
                    Mail = "*****@*****.**"
                },
                new Graph.User
                {
                    DisplayName       = "Jack",
                    UserPrincipalName = "Jack",
                    Id   = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-002",
                    Mail = "*****@*****.**"
                },
                new Graph.User
                {
                    DisplayName       = "Jack",
                    UserPrincipalName = "Jack",
                    Id   = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-003",
                    Mail = "*****@*****.**"
                }
            };

            graphGroups = new List <Graph.Group>()
            {
                new Graph.Group
                {
                    DisplayName = "Jack",
                    Id          = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-001",
                    Mail        = "*****@*****.**"
                },
                new Graph.Group
                {
                    DisplayName = "Jack",
                    Id          = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-002",
                    Mail        = "*****@*****.**"
                },
                new Graph.Group
                {
                    DisplayName = "Jack",
                    Id          = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-003",
                    Mail        = "*****@*****.**"
                }
            };

            graphGroupDirectoryObject = new List <Graph.DirectoryObject>()
            {
                new Graph.DirectoryObject
                {
                    Id = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-001"
                },
                new Graph.DirectoryObject
                {
                    Id = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-002"
                },
                new Graph.DirectoryObject
                {
                    Id = "ad4b2b43-1cb5-408d-ab8a-17e28edac2ba-445567-999-003"
                }
            };

            fileInfo = new FormFile(new MemoryStream(), 1, 1, "sample.jpeg", "sample.jpeg");

            teamsChannelAccount = new List <TeamsChannelAccount>()
            {
                new TeamsChannelAccount
                {
                    GivenName         = "sam",
                    UserPrincipalName = "s"
                },
                new TeamsChannelAccount
                {
                    GivenName         = "jack",
                    UserPrincipalName = "j"
                }
            };
        }
        /// <summary>
        /// Create adaptive card attachment for a team which needs to be sent after creating new event.
        /// </summary>
        /// <param name="applicationBasePath">Base URL of application.</param>
        /// <param name="localizer">String localizer for localizing user facing text.</param>
        /// <param name="eventEntity">Event details of newly created event.</param>
        /// <param name="createdByName">Name of person who created event.</param>
        /// <returns>An adaptive card attachment.</returns>
        public static Attachment GetEventCreationCardForTeam(string applicationBasePath, IStringLocalizer <Strings> localizer, EventEntity eventEntity, string createdByName)
        {
            eventEntity = eventEntity ?? throw new ArgumentNullException(nameof(eventEntity), "Event details cannot be null");

            AdaptiveCard lnDTeamCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Medium,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Height = AdaptiveHeight.Auto,
                                Width  = AdaptiveColumnWidth.Auto,
                                Items  = !string.IsNullOrEmpty(eventEntity.Photo) ? new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url = new Uri(eventEntity.Photo),
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                        PixelHeight         = 45,
                                        PixelWidth          = 45,
                                    },
                                }
                                :
                                new List <AdaptiveElement>(),
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = eventEntity.Name,
                                        Size   = AdaptiveTextSize.Large,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Text    = eventEntity.CategoryName,
                                        Wrap    = true,
                                        Size    = AdaptiveTextSize.Small,
                                        Weight  = AdaptiveTextWeight.Bolder,
                                        Color   = AdaptiveTextColor.Warning,
                                        Spacing = AdaptiveSpacing.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Medium,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("DateAndTimeLabel")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = string.Format(CultureInfo.CurrentCulture, "{0} {1}-{2}", "{{DATE(" + eventEntity.StartDate.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture) + ", SHORT)}}", "{{TIME(" + eventEntity.StartTime.Value.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}", "{{TIME(" + eventEntity.EndTime.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}"),
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = eventEntity.Type != (int)EventType.InPerson ? new List <AdaptiveColumn>() : new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("Venue")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.Venue,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("DescriptionLabelCard")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.Description,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("NumberOfRegistrations")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.RegisteredAttendeesCount.ToString(CultureInfo.InvariantCulture),
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = $"{localizer.GetString("CreatedByLabel")} **{createdByName}**",
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveImage
                    {
                        IsVisible           = eventEntity.Audience == (int)EventAudience.Private,
                        Url                 = new Uri($"{applicationBasePath}/images/Private.png"),
                        PixelWidth          = 84,
                        PixelHeight         = 32,
                        Spacing             = AdaptiveSpacing.Large,
                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("EditEventCardButton"),
                        Data  = new AdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type = "task/fetch",
                                Text = localizer.GetString("EditEventCardButton"),
                            },
                            Command = BotCommands.EditEvent,
                            EventId = eventEntity.EventId,
                            TeamId  = eventEntity.TeamId,
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("CloseRegistrationCardButton"),
                        Data  = new AdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type = "task/fetch",
                                Text = localizer.GetString("CloseRegistrationCardButton"),
                            },
                            Command = BotCommands.CloseRegistration,
                            EventId = eventEntity.EventId,
                            TeamId  = eventEntity.TeamId,
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = lnDTeamCard,
            });
        }
Exemplo n.º 26
0
        /// <summary>
        /// 独立check逻辑
        /// </summary>
        /// <param name="eventEntity"></param>
        /// <param name="registers"></param>
        /// <param name="userId"></param>
        /// <param name="now"></param>
        /// <returns></returns>
        public ResultResponse <object, EventStatus> CheckinRegister(EventEntity eventEntity,
                                                                    List <EventProfileEntity> registers, string userId, DateTime now)
        {
            if (eventEntity.IsDeleted.GetValueOrDefault())
            {
                return(new ResultResponse <object, EventStatus>
                {
                    Entity = eventEntity,
                    Status = EventStatus.CanceledEvent
                });
            }

            var eventProfile = registers.Find(x => x.UserId == userId && x.IsDeleted == false);

            if (eventProfile != null)
            {
                //注册过了
                return(new ResultResponse <object, EventStatus>
                {
                    Entity = new { Event = eventEntity, Profile = eventProfile },
                    Status = EventStatus.RepeatRegistered
                });
            }

            if (eventEntity.RegisteredStartedDateTime > now)
            {
                return new ResultResponse <object, EventStatus> {
                           Entity = eventEntity, Status = EventStatus.NotStarted
                }
            }
            ;

            if (eventEntity.RegisteredEndedDateTime < now)
            {
                return new ResultResponse <object, EventStatus> {
                           Entity = eventEntity, Status = EventStatus.Finished
                }
            }
            ;

            if (eventEntity.RegisteredStartedDateTime > now || eventEntity.RegisteredEndedDateTime < now)
            {
                return new ResultResponse <object, EventStatus>
                       {
                           Entity = eventEntity,
                           Status = EventStatus.OutOfRegDateRange
                       }
            }
            ;

            if (eventEntity.MaxUser > 0 && registers.Count() + 1 > eventEntity.MaxUser)
            {
                return(new ResultResponse <object, EventStatus>
                {
                    Entity = eventEntity,
                    Status = EventStatus.OverMaxUser
                });
            }

            return(new ResultResponse <object, EventStatus>
            {
                Status = EventStatus.Continue,
                Entity = eventEntity
            });
        }
Exemplo n.º 27
0
        public static async Task <Guid?> CreatePlayerViewAsync(PlayerApiClient playerApiClient, EventEntity eventEntity, Guid parentViewId, CancellationToken ct)
        {
            try
            {
                var view = await playerApiClient.CloneViewAsync(parentViewId, ct);

                view.Name = $"{view.Name.Replace("Clone of ", "")} - {eventEntity.Username}";
                await playerApiClient.UpdateViewAsync((Guid)view.Id, view, ct);

                // add user to first non-admin team
                var roles = await playerApiClient.GetRolesAsync(ct);

                var teams = (await playerApiClient.GetViewTeamsAsync((Guid)view.Id, ct));
                foreach (var team in teams)
                {
                    if (team.Permissions.Where(p => p.Key == "ViewAdmin").Any())
                    {
                        continue;
                    }

                    if (team.RoleId.HasValue)
                    {
                        var role = roles.Where(r => r.Id == team.RoleId).FirstOrDefault();

                        if (role != null && role.Permissions.Where(p => p.Key == "ViewAdmin").Any())
                        {
                            continue;
                        }
                    }

                    await playerApiClient.AddUserToTeamAsync(team.Id, eventEntity.UserId, ct);
                }
                return(view.Id);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 28
0
 internal ICollection <EventTaskAssignment> ReadRunnerReminderCsvForEvent(string filepath, EventEntity evnt)
 {
     return(ReadRunnerReminderCsvForEvent(filepath, evnt.Id));
 }
Exemplo n.º 29
0
 public bool CreatEvent(EventEntity evnt)
 {
     return(hr.Insert(evnt));
 }
Exemplo n.º 30
0
        public void MapEvent()
        {
            //Arrange


            var stageEntity = new StageEntity()
            {
                Id        = Guid.NewGuid(),
                ImagePath = "ImagePath",
                Name      = "Name",
            };

            var stageModel = new StageListModel()
            {
                Id        = stageEntity.Id,
                ImagePath = "ImagePath",
                Name      = "Name",
            };

            var bandEntity = new BandEntity
            {
                Id        = Guid.NewGuid(),
                ImagePath = "ImagePath",
                Name      = "Name",
            };

            var bandModel = new BandListModel()
            {
                Id        = bandEntity.Id,
                ImagePath = "ImagePath",
                Name      = "Name",
            };


            var id = Guid.NewGuid();

            var entity = new EventEntity
            {
                Id      = id,
                Start   = new DateTime(2020, 11, 25, 12, 00, 00),
                End     = new DateTime(2020, 11, 25, 14, 00, 00),
                BandId  = bandEntity.Id,
                Band    = bandEntity,
                StageId = stageEntity.Id,
                Stage   = stageEntity
            };

            var model = new EventDetailModel
            {
                Id      = id,
                Start   = new DateTime(2020, 11, 25, 12, 00, 00),
                End     = new DateTime(2020, 11, 25, 14, 00, 00),
                BandId  = bandModel.Id,
                Band    = bandModel,
                StageId = stageModel.Id,
                Stage   = stageModel
            };


            //Act
            var entityAdapted = model.Adapt <EventEntity>();
            var modelAdapted  = entity.Adapt <EventDetailModel>();


            //Assert
            Assert.Equal(entity, entityAdapted, EventEntity.EventEntityComparer);
            Assert.Equal(model, modelAdapted, EventDetailModel.EventDetailModelComparer);
        }
Exemplo n.º 31
0
 public bool Delete(EventEntity evnt)
 {
     return(hr.Delete(evnt));
 }
Exemplo n.º 32
0
 public static Event Map(EventEntity to)
 {
     return(new Event {
         ID = to.ID, Description = to.Description, CalendarID = to.CalendarID, StartDate = to.StartDate, EndDate = to.EndDate
     });
 }
Exemplo n.º 33
0
 private bool Equals(EventEntity other)
 {
     return(Id == other.Id && string.Equals(Json, other.Json));
 }
Exemplo n.º 34
0
        protected override void Seed(SportsbookDbContext context)
        {
            // Categories
            string[] catNames = new string[] { "Football", "Basketball", "Ice Skating", "Baseball", "Badminton", "Swimming", "American Football", "Boxing", "Biking", "Running" };

            foreach (string catName in catNames)
            {
                var cat = new CategoryEntity()
                {
                    Name = catName
                };

                var subCat = new SubCategoryEntity()
                {
                    Name     = "SubCat" + catName,
                    Category = cat
                };

                context.SubCategoryEntities.Add(subCat);
            }

            context.SaveChanges();

            // Events
            for (int x = 0; x < 10; x++)
            {
                var ev = new EventEntity()
                {
                    Name        = "A" + x.ToString() + " - B" + x.ToString(),
                    StartDate   = DateTime.Now,
                    EndDate     = DateTime.Now.Add(TimeSpan.FromDays(1)),
                    SubCategory = context.SubCategoryEntities.ToList()[x]
                };

                var market = new MarketEntity()
                {
                    MarketGroupName  = "Match Winner",
                    StartDate        = DateTime.Now,
                    EndDate          = DateTime.Now.Add(TimeSpan.FromDays(1)),
                    Event            = ev,
                    MarketSelections = new Collection <MarketSelectionEntity>()
                    {
                        new MarketSelectionEntity()
                        {
                            Odds        = 1.1,
                            DisplayName = "1"
                        },

                        new MarketSelectionEntity()
                        {
                            Odds        = 1.2,
                            DisplayName = "X"
                        },

                        new MarketSelectionEntity()
                        {
                            Odds        = 1.3,
                            DisplayName = "2"
                        },
                    }
                };

                context.MarketEntities.Add(market);
            }


            context.SaveChanges();
        }
Exemplo n.º 35
0
 static IEvent DeserializeEvent(EventEntity eventEntity)
 {
     var eventType = Type.GetType(TypeNameToQuallifiedName(eventEntity.Type), true);
     return (IEvent)JsonConvert.DeserializeObject(eventEntity.Data, eventType, SerializerSettings);
 }
Exemplo n.º 36
0
 EntityOperation EventEntity(Partition partition)
 {
     var entity = new EventEntity(partition, this);
     return new EntityOperation.Insert(entity);
 }