Beispiel #1
0
        public void CreateEvent(string name, string description, DateTime?dateTime, int maximumTickets, string photoPath, string locationCity, string locationCountry, SubTypeEnum subTypeName, string artistName, Ticket ticket)
        {
            var location = locationRepository.GetLocationByCityAndCountry(locationCity, locationCountry);

            if (location == null)
            {
                throw new Exception("The location does not exist!");
            }

            var subType = eventSubTypeRepository.GetSubTypeByName(subTypeName);

            if (subType == null)
            {
                throw new Exception("The subtype does not exist!");
            }

            var typeName = subType.TypeParent.Name;
            var type     = eventTypeRepository.GetEventTypeByName(typeName);

            if (type == null)
            {
                throw new Exception("The type does not exist!");
            }
            var artist = artistsRepository.GetArtistByName(artistName);

            if (artist == null)
            {
                throw new Exception("The artist does not exist!");
            }

            if (ticket == null)
            {
                throw new Exception("The ticket does not exist!");
            }

            Event newEvent = new Event {
                Id = Guid.NewGuid(), Name = name, Description = description, DateTime = dateTime, MaximumTickets = maximumTickets, CoverPhotoPath = photoPath, Location = location, Type = type, SubType = subType, Artist = artist, AvailableTickets = maximumTickets, Ticket = ticket
            };

            ticket.TicketEvent = newEvent;
            ticket.EventId     = newEvent.Id;
            eventRepository.Add(newEvent);
        }