public TourArtefactDto Create(TourArtefactDto dto)
        {
            if (dto.Order < 0)
            {
                throw new ArgumentNullException("Order must be a position Number");
            }

            var tour = Db.Tours.Find(dto.Tour.Id);

            if (tour == null || (tour.Artefacts != null && tour.Artefacts.Any(m => m.Order == dto.Order)))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            TourArtefact tourArtefact = new TourArtefact()
            {
                Order        = dto.Order,
                Artefact     = Db.Artefacts.Find(dto.Artefact.Id),
                Tour         = Db.Tours.Find(dto.Tour.Id),
                CreatedDate  = DateTime.UtcNow,
                ModifiedDate = DateTime.UtcNow,
                IsDeleted    = false
            };

            Db.TourArtefacts.Add(tourArtefact);

            Db.SaveChanges();

            return(Mapper.Map <TourArtefactDto>(tourArtefact));
        }
        public TourArtefactDto Update(TourArtefactDto dto)
        {
            if (dto.Order < 0)
            {
                throw new ArgumentNullException("Order must be a position Number");
            }

            var tour = Db.Tours.Find(dto.Tour.Id);

            if (tour == null || (tour.Artefacts == null))             // && tour.Artefacts.Any(m => m.Id != dto.Id && m.Order == dto.Order)))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            TourArtefact tourArtefact = Db.TourArtefacts.Include("Artefact").Include("Tour").FirstOrDefault(m => m.Id == dto.Id);

            if (tourArtefact == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            tourArtefact.Order        = dto.Order;
            tourArtefact.ModifiedDate = DateTime.UtcNow;

            Db.SaveChanges();

            return(Mapper.Map <TourArtefactDto>(tourArtefact));
        }
        public TourArtefactDto GetById(int tourArtefactId)
        {
            TourArtefact tourArtefact = Db.TourArtefacts.Find(tourArtefactId);

            if (tourArtefact == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return(Mapper.Map <TourArtefactDto>(tourArtefact));
        }
        public bool Delete(int artefactId)
        {
            TourArtefact tourArtefact = Db.TourArtefacts.Include("Artefact").Include("Tour").FirstOrDefault(m => m.Id == artefactId);

            if (tourArtefact == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            tourArtefact.IsDeleted = true;

            Db.SaveChanges();

            return(true);
        }