Esempio n. 1
0
        public EventSubType GetSubTypeByName(SubTypeEnum subTypeName)
        {
            var subType = context.EventSubTypes.SingleOrDefault(s => s.Name == subTypeName);

            subType.TypeParent = context.EventTypes.Find(subType.TypeParentId);
            return(subType);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public Event UpdateEvent(Guid id, string name, string description, DateTime?dateTime, int maximumTickets, string photoPath, string locationCity, string locationCountry, SubTypeEnum subTypeName, string artistName, Ticket ticket)
        {
            var oldEvent = GetEventById(id);

            if (oldEvent != null)
            {
                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!");
                }

                var oldTicket = ticketRepository.GetById(oldEvent.TicketId);
                if (oldTicket == null)
                {
                    throw new Exception("The ticket does not exist!");
                }

                oldTicket.Price = ticket.Price;

                oldEvent.Name             = name;
                oldEvent.Artist           = artist;
                oldEvent.MaximumTickets   = maximumTickets;
                oldEvent.AvailableTickets = oldEvent.MaximumTickets;
                oldEvent.CoverPhotoPath   = photoPath;
                oldEvent.DateTime         = dateTime;
                oldEvent.Description      = description;
                oldEvent.Location         = location;
                oldEvent.SubType          = subType;
                oldEvent.Type             = type;
                oldEvent.Ticket           = oldTicket;
            }

            eventRepository.Update(oldEvent);
            return(oldEvent);
        }