Ejemplo n.º 1
0
        public async Task <bool> ExcursionCreate(ExcursionCreateInputModel model)
        {
            var validLanguageIds = new HashSet <int>(await languageServices.GetAll().Select(l => l.Id).ToListAsync());

            var excursionToAdd = new Excursion()
            {
                Arrival         = model.Arrival,
                Departure       = model.Departure,
                LastUpdated     = model.LastUpdated,
                TouristCapacity = model.TouristCapacity,
                LastUpdatedBy   = model.LastUpdatedBy,
                EndPoint        = model.EndPoint,
                PricePerAdult   = model.Price,
                PricePerChild   = model.ChildPrice,
                StartingPoint   = model.StartingPoint,
                ExcursionTypeId = model.ExcursionTypeId
            };

            excursionToAdd.LanguageExcursions = model
                                                .LanguageIds.Where(l => validLanguageIds.Contains(l))
                                                .Distinct()
                                                .Select(id => new LanguageExcursion()
            {
                Excursion  = excursionToAdd,
                LanguageId = id
            })
                                                .ToList();

            await context.Excursions.AddAsync(excursionToAdd);

            await context.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <ExcursionCreateInputModel> ExcursionGetById(int id)
        {
            //we don`t include the types and language, because of the multiple-choice select!
            var excursion = await context.Excursions.FindAsync(id);

            var inputModel = new ExcursionCreateInputModel()
            {
                Id              = excursion.Id,
                Arrival         = excursion.Arrival,
                Departure       = excursion.Departure,
                EndPoint        = excursion.EndPoint,
                LastUpdated     = excursion.LastUpdated,
                LastUpdatedBy   = excursion.LastUpdatedBy,
                Price           = excursion.PricePerAdult,
                StartingPoint   = excursion.StartingPoint,
                TouristCapacity = excursion.TouristCapacity,
                Languages       = await languageServices.GetAll().Select(l => new LanguageViewModel()
                {
                    Id   = l.Id,
                    Name = l.Name
                })
                                  .ToListAsync(),

                ExcursionTypes = await context.ExcursionTypes.Select(e => new ExcursionTypeViewModel()
                {
                    Id   = e.Id,
                    Name = e.Name
                })
                                 .ToListAsync()
            };

            return(inputModel);
        }
        public async Task <IActionResult> EditExcursion(ExcursionCreateInputModel model)
        {
            model.LastUpdatedBy = User.Identity.Name;
            bool isValid = await excursionServices.ExcursionEdit(model);

            //TODO: here maybe a proper error throw

            return(this.Redirect($"/Excursion/ExcursionOperator/DetailsExcursion?id={model.Id}"));
        }
        public async Task <IActionResult> CreateExcursion()
        {
            var inputModel = new ExcursionCreateInputModel()
            {
                ExcursionTypes = await excursionServices.ExcursionTypesGetAll().ToListAsync(),
                Languages      = await languageServices.GetAll().ToListAsync()
            };

            return(this.View(inputModel));
        }
Ejemplo n.º 5
0
        public async Task <bool> ExcursionEdit(ExcursionCreateInputModel model)
        {
            var modelToEdit = await context.
                              Excursions
                              .Include(e => e.LanguageExcursions)
                              .Include(e => e.ExcursionType)
                              .FirstOrDefaultAsync(x => x.Id == model.Id);

            context.LanguageExcursions.RemoveRange(modelToEdit.LanguageExcursions);

            //WHY ON EARTH DID THIS THING SCREWED EVERYTHING UP? ( I HAVE REFERENCES!!)
            modelToEdit.LanguageExcursions.Clear();


            var excursionTypeToBreak = await context.ExcursionTypes.FindAsync(modelToEdit.ExcursionTypeId);

            excursionTypeToBreak.Excursions.Remove(modelToEdit);

            modelToEdit.LanguageExcursions = model.LanguageIds.Select(l => new LanguageExcursion
            {
                Excursion  = modelToEdit,
                LanguageId = l
            })
                                             .ToList();

            modelToEdit.LastUpdated     = DateTime.UtcNow;
            modelToEdit.LastUpdatedBy   = model.LastUpdatedBy;
            modelToEdit.PricePerAdult   = model.Price;
            modelToEdit.StartingPoint   = model.StartingPoint;
            modelToEdit.TouristCapacity = model.TouristCapacity;
            modelToEdit.Arrival         = model.Arrival;
            modelToEdit.Departure       = model.Departure;
            modelToEdit.EndPoint        = model.EndPoint;
            modelToEdit.ExcursionTypeId = model.ExcursionTypeId;

            await context.LanguageExcursions.AddRangeAsync(modelToEdit.LanguageExcursions);

            await context.SaveChangesAsync();


            return(true);
        }
        public async Task <IActionResult> CreateExcursion(ExcursionCreateInputModel model)
        {
            //TODO: validate before/after date to be meaningful + some bug with the requirement for date
            model.LastUpdated   = DateTime.UtcNow;
            model.LastUpdatedBy = HttpContext.User.Identity.Name;

            if (!ModelState.IsValid)
            {
                model.ExcursionTypes = await excursionServices.ExcursionTypesGetAll().ToListAsync();

                model.Languages = await languageServices.GetAll().ToListAsync();

                return(this.View(model));
            }


            bool isValid = await excursionServices.ExcursionCreate(model);

            return(Redirect("/Excursion/ExcursionOperator/ViewAllExcursions"));
        }