public async Task <EventCustomer> CreateAsync(EventCustomer model)
        {
            EventsCustomers eventDataAccess = Mapper.Map <EventCustomer, EventsCustomers>(model);

            _db.Add(eventDataAccess);

            model = Mapper.Map <EventsCustomers, EventCustomer>(eventDataAccess);
            return(model);
        }
        public async Task DeleteAsync(int id)
        {
            //EventsCustomers tracked = Mapper.Map<Event, EventsCustomers>(GetById(id));
            EventsCustomers tracked = _db.EventsCustomers.Find(id);

            if (tracked == null)
            {
                throw new ArgumentException("No EventCustomerwith this id", nameof(id));
            }
            _db.Remove(tracked);
        }
        public async Task <EventCustomer> UpdateAsync(EventCustomer model, int?id = null)
        {
            EventsCustomers eventDataAccess = Mapper.Map <EventCustomer, EventsCustomers>(model);

            if (id == null)
            {
                throw new ArgumentException("Nedded id", nameof(id));
            }

            EventsCustomers tracked = _db.EventsCustomers.Find(id);

            if (tracked == null)
            {
                throw new ArgumentException("No EventCustomerwith this id", nameof(id));
            }

            _db.Entry(tracked).CurrentValues.SetValues(eventDataAccess);
            model = Mapper.Map <EventsCustomers, EventCustomer>(eventDataAccess);

            return(model);
        }
        public async Task <EventCustomer> GetByIdAsync(int id)
        {
            EventsCustomers eventCustomer = _db.EventsCustomers
                                            .Include(ec => ec.Customer)
                                            .Include(ev => ev.Event)
                                            .SingleOrDefault(e => e.Id == id);

            if (eventCustomer != null)
            {
                if (eventCustomer.Customer != null)
                {
                    eventCustomer.Customer.EventsCustomers = null;
                }
                if (eventCustomer.Event != null)
                {
                    eventCustomer.Event.EventsCustomers = null;
                }

                return(Mapper.Map <EventsCustomers, EventCustomer>(eventCustomer));
            }
            return(null);
        }