public async Task <IActionResult> DeleteVideo(int id)
        {
            var model = await GenericGetDataClass <VideoModel> .GetAllData($"api/video/{id}");

            var response = await GenericGetDataClass <VideoModel> .DeleteData($"api/deletevideo/{id}");

            if (response)
            {
                var webRootPath = _hostingEnvironment.WebRootPath;

                // Получаем путь из модели и удаляем первый символ (/)
                var replacedPath = model.Path.Substring(1);
                var path         = Path.Combine(webRootPath, replacedPath);

                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }

                TempData["SM"] = "Видео успешно удалено!";
                return(RedirectToAction(nameof(ShowAllVideo)));
            }
            else
            {
                //TODO: вывод ошибок
                return(RedirectToAction(nameof(ShowAllVideo)));
            }
        }
        public async Task <IActionResult> AddVideo()
        {
            var categories = await GenericGetDataClass <List <CategoryModel> > .GetAllData("api/categories");

            ViewData["CategoryList"] = categories.ToList();
            return(View());
        }
        public async Task <IActionResult> DeleteCategory(int id)
        {
            var response = await GenericGetDataClass <Category> .DeleteCategory($"api/delete/{id}");

            if (response)
            {
                TempData["SM"] = "Category deleting successful!";
                return(RedirectToAction(nameof(ShowAllCategories)));
            }

            TempData["SM"] = "Something wrong";
            return(RedirectToAction(nameof(ShowAllCategories)));
        }
        public async Task <IActionResult> DeleteUser(int id)
        {
            var response = await GenericGetDataClass <EmployeeModel> .DeleteData($"api/deleteuser/{id}");

            if (response)
            {
                TempData["SM"] = "Пользователь успешно удален!";
                return(RedirectToAction(nameof(ShowAllUsers)));
            }
            else
            {
                return(View());
            }
        }
        public async Task <IActionResult> DeleteCategory(int id)
        {
            var response = await GenericGetDataClass <CategoryModel> .DeleteData($"api/deletecategory/{id}");

            if (response)
            {
                TempData["SM"] = "Категория успешно удалена!";
                return(RedirectToAction(nameof(ShowAllCategories)));
            }
            else
            {
                return(View());
            }
        }
        public async Task <IActionResult> EditUser(EmployeeModel editedUser)
        {
            if (!ModelState.IsValid)
            {
                return(View(editedUser));
            }
            var response = await GenericGetDataClass <EmployeeModel> .EditData("api/edituser", editedUser);

            if (response)
            {
                TempData["SM"] = "Пользователь успешно отредактирован!";
                return(RedirectToAction(nameof(ShowAllUsers)));
            }
            else
            {
                return(View(editedUser));
            }
        }
        public async Task <IActionResult> EditCategory(Category editedCategory)
        {
            if (!ModelState.IsValid)
            {
                return(View(editedCategory));
            }

            var response = await GenericGetDataClass <Category> .EditCategoryData($"api/edit", editedCategory);

            if (response)
            {
                TempData["SM"] = "Selected category edit successful!";
                return(RedirectToAction(nameof(ShowAllCategories)));
            }
            else
            {
                return(View(editedCategory));
            }
        }
        public async Task <IActionResult> EditCategory(CategoryModel editedCategory)
        {
            if (!ModelState.IsValid)
            {
                return(View(editedCategory));
            }

            var response = await GenericGetDataClass <CategoryModel> .EditData("api/editcategory", editedCategory);

            if (response)
            {
                TempData["SM"] = "Категория успешно отредактирована!";
                return(RedirectToAction(nameof(ShowAllCategories)));
            }
            else
            {
                return(View(editedCategory));
            }
        }
        public async Task <IActionResult> EditVideo(VideoModel editedVideo)
        {
            if (!ModelState.IsValid)
            {
                return(View(editedVideo));
            }

            var response = await GenericGetDataClass <VideoModel> .EditData("api/editvideo", editedVideo);

            if (response)
            {
                TempData["SM"] = "Видео успешно отредактировано!";
                return(RedirectToAction(nameof(ShowAllVideo)));
            }
            else
            {
                return(View(editedVideo));
            }
        }
        public async Task <IActionResult> AddCategory(Category addedCategory)
        {
            if (!ModelState.IsValid)
            {
                return(View(addedCategory));
            }

            var response = await GenericGetDataClass <Category> .AddCategoryData($"api/add", addedCategory);

            if (response)
            {
                TempData["SM"] = $"Add category {addedCategory.Name} successful!";
                return(RedirectToAction(nameof(ShowAllCategories)));
            }
            else
            {
                return(View(addedCategory));
            }
        }
        public async Task <IActionResult> AddCategory(CategoryModel addCategoryModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(addCategoryModel));
            }

            var response = await GenericGetDataClass <CategoryModel> .AddData("api/addcategory", addCategoryModel);

            if (response)
            {
                TempData["SM"] = "Категория успешно добавлена!";
                return(RedirectToAction(nameof(ShowAllCategories)));
            }
            else
            {
                return(View(addCategoryModel));
            }
        }
        public async Task <IActionResult> EditCategory(int id)
        {
            var category = await GenericGetDataClass <CategoryModel> .GetAllData($"api/category/{id}");

            return(View(category));
        }
        public async Task <IActionResult> ShowAllVideo()
        {
            var videos = await GenericGetDataClass <List <VideoModel> > .GetAllData("api/videos");

            return(View(videos));
        }
        public async Task <IActionResult> EditVideo(int id)
        {
            var video = await GenericGetDataClass <VideoModel> .GetAllData($"api/video/{id}");

            return(View(video));
        }
        public async Task <IActionResult> EditUser(int id)
        {
            var user = await GenericGetDataClass <EmployeeModel> .GetAllData($"api/user/{id}");

            return(View(user));
        }
        public async Task <IActionResult> ShowAllCategories()
        {
            var categories = await GenericGetDataClass <List <CategoryModel> > .GetAllData("api/categories");

            return(View(categories));
        }
        public async Task <IActionResult> ShowAllUsers()
        {
            var users = await GenericGetDataClass <IEnumerable <EmployeeModel> > .GetAllData("api/users");

            return(View(users));
        }
        public async Task <IActionResult> AddVideo(VideoVM addedVideo, IFormFile[] file)
        {
            if (file == null || file.Length == 0)
            {
                ModelState.AddModelError("", "Видеофайл не выбран, пожалуйста, добавьте видео и попробуйте снова");
                return(View(addedVideo));
            }

            #region Save video file
            if (file.Length == 1)
            {
                if (!ModelState.IsValid)
                {
                    return(View(addedVideo));
                }

                // Формируем пути
                var webRootPath   = _hostingEnvironment.WebRootPath;
                var extension     = Path.GetExtension(file[0].FileName);
                var uploads       = Path.Combine(webRootPath, SD.VideosFolder, addedVideo.VideoModel.Name + extension);
                var pathToVideo   = Path.Combine("\\" + SD.VideosFolder, addedVideo.VideoModel.Name + extension);
                var directoryPath = Path.Combine(webRootPath, SD.VideosFolder);
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
                addedVideo.VideoModel.Path = pathToVideo;

                var response = await GenericGetDataClass <VideoVM> .AddData("api/addvideo", addedVideo);

                if (response)
                {
                    var   stream = new FileStream(uploads, FileMode.Create);
                    await file[0].CopyToAsync(stream);
                    stream.Close();

                    TempData["SM"] = "Видео успешно добавлено!";
                    return(RedirectToAction(nameof(ShowAllVideo)));
                }
                else
                {
                    ModelState.AddModelError("", "Ошибка сохранения данных");
                    return(View(addedVideo));
                }

                #endregion
            }
            else
            {
                var webRootPath   = _hostingEnvironment.WebRootPath;
                var directoryPath = Path.Combine(webRootPath, SD.VideosFolder);
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
                foreach (var item in file)
                {
                    string extension = Path.GetExtension(item.FileName);
                    addedVideo.VideoModel.Name       = String.Format(System.Guid.NewGuid() + extension);
                    addedVideo.VideoModel.CategoryId = 1;
                    var uploads     = Path.Combine(webRootPath, SD.VideosFolder, addedVideo.VideoModel.Name + extension);
                    var pathToVideo = Path.Combine("\\" + SD.VideosFolder, addedVideo.VideoModel.Name + extension);
                    addedVideo.VideoModel.Path = pathToVideo;
                    var response = await GenericGetDataClass <VideoVM> .AddData("api/addvideo", addedVideo);

                    if (response)
                    {
                        var stream = new FileStream(uploads, FileMode.Create);
                        await item.CopyToAsync(stream);

                        stream.Close();
                    }
                    else
                    {
                        ModelState.AddModelError("", "Ошибка сохранения данных");
                        return(View(addedVideo));
                    }
                }
                TempData["SM"] = "Видео успешно добавлены!";
                return(RedirectToAction(nameof(ShowAllVideo)));
            }
        }
        public async Task <IActionResult> ShowOneCategory(int id)
        {
            var category = await GenericGetDataClass <Category> .GetCategoryData($"api/category/{id}");

            return(View(category));
        }