Example #1
0
        public async Task <IActionResult> OnPostSyncAsync(string returnUrl = "")
        {
            var user = await _userManager.GetUserAsync(User);

            if (user is null)
            {
                return(RedirectToPage("/Account/Errors/AccessDenied", new { Area = "Identity" }));
            }
            if (user.Role != Roles.Admin)
            {
                return(RedirectToPage("/Account/Errors/AccessDenied", new { Area = "Identity" }));
            }
            // Categories seed
            var catategoriesResult = await _categoriesService.SeedCategories();

            if (catategoriesResult.Success)
            {
                await _notifyService.Create("Categories were added succesfuly.", $"categories/index", DateTime.Now, NotifyType.Success, "flaticon-database", user);
            }
            else
            {
                await _notifyService.Create($"{catategoriesResult.FailureMessage}", $"categories/index", DateTime.Now, NotifyType.Danger, "flaticon-database", user);
            }


            // Locations seed
            var locationsResult = await _locationService.SeedLocation();

            if (locationsResult.Success)
            {
                await _notifyService.Create("Locations were added succesfuly.", $"categories/index", DateTime.Now, NotifyType.Success, "flaticon-database", user);
            }
            else
            {
                await _notifyService.Create($"{locationsResult.FailureMessage}", $"categories/index", DateTime.Now, NotifyType.Danger, "flaticon-database", user);
            }

            // Languages seed
            var languagesResult = await _langService.SeedLanguages();

            if (languagesResult.Success)
            {
                await _notifyService.Create("Languages were added succesfuly.", $"categories/index", DateTime.Now, NotifyType.Success, "flaticon-database", user);
            }
            else
            {
                await _notifyService.Create($"{languagesResult.FailureMessage}", $"categories/index", DateTime.Now, NotifyType.Danger, "flaticon-database", user);
            }


            // Skills seed
            var skillsResult = await _skillsService.SeedSkills();

            if (skillsResult.Success)
            {
                await _notifyService.Create("Skills were added succesfuly.", $"categories/index", DateTime.Now, NotifyType.Success, "flaticon-database", user);
            }
            else
            {
                await _notifyService.Create($"{skillsResult.FailureMessage}", $"categories/index", DateTime.Now, NotifyType.Danger, "flaticon-database", user);
            }

            if (!String.IsNullOrEmpty(returnUrl))
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(RedirectToPage("/Account/Manage/Index", new { Area = "Identity" }));
            }
        }