Esempio n. 1
0
        public static async Task <IDisposableEntity <EventInfo> > CreateEventAsync(
            this ApplicationDbContext context,
            string title       = Placeholder,
            string description = Placeholder,
            string code        = Placeholder,
            string city        = Placeholder,
            EventInfo.EventInfoType eventInfoType = EventInfo.EventInfoType.Conference,
            bool featured      = false,
            DateTime?dateStart = null,
            DateTime?dateEnd   = null,
            Product[] products = null)
        {
            if (title == Placeholder)
            {
                title = $"Test Event {Guid.NewGuid()}";
            }

            if (description == Placeholder)
            {
                description = $"Test Event Description {Guid.NewGuid()}";
            }

            if (code == Placeholder)
            {
                code = Guid.NewGuid().ToString();
            }

            var eventInfo = new EventInfo
            {
                Title       = title,
                Description = description,
                Code        = code,
                Featured    = featured,
                DateStart   = dateStart,
                DateEnd     = dateEnd,
                Type        = eventInfoType,
                City        = city,
                Products    = products?.ToList()
            };

            context.EventInfos.Add(eventInfo);
            await context.SaveChangesAsync();

            return(new DisposableEntity <EventInfo>(eventInfo, context));
        }
        public static async Task <IDisposableEntity <EventInfo> > CreateEventAsync(
            this TestServiceScope scope,
            string title       = TestingConstants.Placeholder,
            string description = TestingConstants.Placeholder,
            string slug        = TestingConstants.Placeholder,
            string city        = TestingConstants.Placeholder,
            EventInfo.EventInfoStatus status      = EventInfo.EventInfoStatus.RegistrationsOpen,
            EventInfo.EventInfoType eventInfoType = EventInfo.EventInfoType.Conference,
            bool featured                 = false,
            LocalDate?dateStart           = null,
            LocalDate?dateEnd             = null,
            Product[] products            = null,
            Organization organization     = null,
            int organizationId            = TestingConstants.OrganizationId,
            int maxParticipants           = 0,
            EventCollection collection    = null,
            EventCollection[] collections = null,
            bool archived                 = false)
        {
            if (title == TestingConstants.Placeholder)
            {
                title = $"Test Event {Guid.NewGuid()}";
            }

            if (description == TestingConstants.Placeholder)
            {
                description = $"Test Event Description {Guid.NewGuid()}";
            }

            if (slug == TestingConstants.Placeholder)
            {
                slug = Guid.NewGuid().ToString();
            }

            if (city == TestingConstants.Placeholder)
            {
                city = "Oslo";
            }

            if (collections == null && collection != null)
            {
                collections = new[] { collection };
            }

            var eventInfo = new EventInfo
            {
                Title              = title,
                Description        = description,
                Slug               = slug,
                Featured           = featured,
                DateStart          = dateStart,
                DateEnd            = dateEnd,
                Type               = eventInfoType,
                City               = city,
                Status             = status,
                MaxParticipants    = maxParticipants,
                Products           = products?.ToList(),
                Archived           = archived,
                OrganizationId     = organization?.OrganizationId ?? organizationId,
                CollectionMappings = collections?.Select(c => new EventCollectionMapping
                {
                    CollectionId = c.CollectionId
                }).ToList()
            };
            await scope.Db.EventInfos.AddAsync(eventInfo);

            await scope.Db.SaveChangesAsync();

            return(new DisposableEntity <EventInfo>(eventInfo, scope.Db));
        }