//Connect and Disconnect for Route
        public async Task <IActionResult> ConnectRouteAndAlbum(ConnectRouteAndAlbumInputModel model)
        {
            try
            {
                bool result = await this.connectService.ConnectAlbumAndRoute(model.AlbumId, model.RouteId);

                if (result)
                {
                    AddSuccessNotification(Notifications.Success);
                }
                else
                {
                    AddDangerNotification(Notifications.Fail);
                }

                return(Redirect($"/Routes/Details/{model.RouteId}"));
            }
            catch (System.Exception e)
            {
                logger.LogError(string.Format(SetLog.Error,
                                              CurrentUser.UserName,
                                              CurrentController,
                                              e.Message));

                AddDangerNotification(string.Format(Notifications.Fail));
                return(Redirect("/"));
            }
        }
Esempio n. 2
0
        public async Task ConnectRouteAndAlbum_OnConnectFalse()
        {
            var service = new Mock <IConnectService>();

            service.Setup(s => s.ConnectAlbumAndRoute("aId", "rId"))
            .ReturnsAsync(() => false);

            ConnectRouteAndAlbumInputModel model = new ConnectRouteAndAlbumInputModel
            {
                AlbumId = "aId",
                RouteId = "rId"
            };

            ConnectController controller = new ConnectController(
                service.Object, userManager.Object, logger)
            {
                TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object)
            };
            var result = await controller.ConnectRouteAndAlbum(model);

            var viewResult = Assert.IsAssignableFrom <RedirectResult>(result);

            viewResult.Url.ShouldBe("/Routes/Details/rId");
            controller.TempData.ContainsKey("notification").ShouldBeTrue();
            controller.TempData["notification"].ShouldNotBeNull();
            controller.TempData["notification"].ShouldBeOfType <string[]>();
            string[] arr = controller.TempData["notification"] as string[];
            arr[0].ShouldBe("danger");
        }
        public async Task <IViewComponentResult> InvokeAsync(string routeId)
        {
            ConnectRouteAndAlbumInputModel model = new ConnectRouteAndAlbumInputModel();

            model.RouteId = routeId;

            User user = await this.userManager.GetUserAsync(this.UserClaimsPrincipal);

            this.TempData["albumList"] = user.Albums.ToList();

            return(View(model));
        }