Beispiel #1
0
        public DestinationRoutes(IDestinationService desService)
            : base("v1")
        {
            this.RequiresAuthentication();

            Get("/destination/{name}", _ =>
            {
                this.RequiresClaims(c => c.Type == HttpMethod.Get.Verb());
                var name = (string)_.name;
                ValidateRequest(name, Context.User().Destinations);
                Destination destination = desService.GetByName(name);
                return(AddDestinationCategoriesToProperties(destination).ToViewModel <Destination, ADModel.Destination>());
            });

            Get("/destinations", _ =>
            {
                this.RequiresClaims(c => c.Type == HttpMethod.Get.Verb());
                var destinations = desService.GetAll();

                // retrieve permitted destinations
                var permittedDestinations = FilterDestinations(destinations, Context.User().Destinations);

                return(AddListDestinationsCategoriesToProperties(permittedDestinations).ToViewModel <List <Destination>, List <ADModel.Destination> >());
            });
        }
Beispiel #2
0
        public CategoryViewModel Post([FromBody] CategoryViewModel viewModel)
        {
            List <DestinationViewModel> destinations = new List <DestinationViewModel>();

            foreach (var destination in viewModel.Destinations)
            {
                Business.Modules.Destination.Model.Destination destinationDetail = null;

                if (!string.IsNullOrEmpty(destination.Name))
                {
                    destinationDetail = _destinationSvc.GetByName(destination.Name);
                }
                if (destinationDetail != null)
                {
                    if (!string.IsNullOrEmpty(destination.Categories.First().Name))
                    {
                        if (!string.IsNullOrEmpty(destination.Categories.First().Id))
                        {
                            var category = destinationDetail.Categories.FirstOrDefault(e => e.Id == destination.Categories.First().Id);

                            category.Name     = destination.Categories.First().Name;
                            category.Brands   = destination.Categories.First().Brands;
                            category.TitleIds = destination.Categories.First().TitleIds;
                        }
                        else
                        {
                            var newCategory = new Business.Modules.Destination.Model.Category
                            {
                                Name     = destination.Categories.First().Name,
                                Brands   = destination.Categories.First().Brands,
                                TitleIds = destination.Categories.First().TitleIds
                            };

                            destinationDetail.Categories.Add(newCategory);
                        }
                    }
                    else
                    {
                        destinationDetail.Categories.RemoveAll(e => e.Id == destination.Categories.First().Id);
                    }

                    var blModel = _destinationSvc.Save(destinationDetail);

                    destinations.Add(blModel.ToViewModel <Business.Modules.Destination.Model.Destination, DestinationViewModel>());
                }
            }

            if (string.IsNullOrEmpty(viewModel.Id))
            {
                viewModel.Id = Guid.NewGuid().ToString();
            }

            viewModel.Destinations = destinations.Where(d => d.Categories.Count() > 0).ToList();

            foreach (var destination in viewModel.Destinations)
            {
                destination.Categories = new List <Category> {
                    destination.Categories.FirstOrDefault(e => e.Name == viewModel.Name)
                };
            }

            viewModel.Destinations = viewModel.Destinations.Where(d => d.Categories.FirstOrDefault() != null).ToList();

            return(viewModel);
        }