public async Task <IActionResult> OnPostSave(int?id)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            var task = taskRepository.GetTask(id.Value);

            if (task == null)
            {
                return(NotFound());
            }

            if (string.IsNullOrEmpty(ViewModel.InputFilePath) && ViewModel.InputFileUpload != null)
            {
                ViewModel.InputFilePath = ViewModel.InputFileUpload.ContentDisposition;
            }

            if (!ModelState.IsValid)
            {
                return(OnGet(id));
            }

            task.Name       = ViewModel.Name;
            task.Desc       = ViewModel.Desc;
            task.DueDate    = ViewModel.DueDate;
            task.MaxAttempt = ViewModel.MaxAttempts;
            task.Desc       = ViewModel.Desc;

            taskRepository.Update(task);

            // Change langs
            var taskLanguages = task.SupportedLanguages;
            var allLanguages  = languageRepository.GetAll();

            if (ViewModel.LanguagesId != null && taskLanguages != null && allLanguages != null)
            {
                var taskLanguagesId = new List <int>();

                foreach (var item in taskLanguages)
                {
                    taskLanguagesId.Add(item.SupportedProgrammingLanguageId);
                }

                var langsDifference = FindLangDifference(taskLanguagesId, ViewModel.LanguagesId);

                foreach (var item in langsDifference)
                {
                    var lang = allLanguages.FirstOrDefault(x => x.SupportedProgrammingLanguageId == item);

                    if (task.SupportedLanguages.Contains(lang))
                    {
                        task.SupportedLanguages.Remove(lang);
                    }
                    else
                    {
                        task.SupportedLanguages.Add(lang);
                    }
                }

                taskRepository.Update(task);
            }

            // change students
            var taskStudents       = task.Assignees;
            var tournamentStudents = userRepository.GetStudentsWithTournament(task.Tournament.TournamentId);

            if (ViewModel.StudentsId != null && taskStudents != null && tournamentStudents != null)
            {
                var taskStudentsId = new List <string>();

                foreach (var item in taskStudents)
                {
                    taskStudentsId.Add(item.User.Id);
                }

                var studentsDifference = FindStudentsDifference(taskStudentsId, ViewModel.StudentsId);

                foreach (var item in studentsDifference)
                {
                    var student  = tournamentStudents.FirstOrDefault(x => x.Id == item);
                    var assignee = task.Assignees.FirstOrDefault(x => x.User == student);

                    if (assignee != null)
                    {
                        task.Assignees.Remove(assignee);
                    }
                    else
                    {
                        TournamentTaskAssignment assignment = new TournamentTaskAssignment
                        {
                            User     = student,
                            Attempts = 0,
                            IsPassed = false,
                            Task     = task
                        };

                        task.Assignees.Add(assignment);

                        taskRepository.Update(task);
                    }
                }
            }

            // upload file
            StorageManager       storageManager       = new StorageManager();
            TournamentRepository tournamentRepository = new TournamentRepository(context);

            var tournament = tournamentRepository.GetTournamentByTask(task.TournamentTaskId);

            if (ViewModel.InputFileUpload != null && ViewModel.InputFileUpload.Length != 0)
            {
                if (tournament != null)
                {
                    var inputFilePath = storageManager.CreateInputFile(tournament.TournamentId.ToString(), task.TournamentTaskId.ToString());
                    using (var stream = new FileStream(inputFilePath, FileMode.Create))
                    {
                        await ViewModel.InputFileUpload.CopyToAsync(stream);
                    }

                    task.InputFilePath = inputFilePath;
                    taskRepository.Update(task);
                }
            }

            if (ViewModel.ExpectedFileUpload != null && ViewModel.ExpectedFileUpload.Length != 0)
            {
                if (tournament != null)
                {
                    var expectedFilePath = storageManager.CreateExpectedFile(tournament.TournamentId.ToString(), task.TournamentTaskId.ToString());
                    using (var stream = new FileStream(expectedFilePath, FileMode.Create))
                    {
                        await ViewModel.ExpectedFileUpload.CopyToAsync(stream);
                    }

                    task.ExpectedFilePath = expectedFilePath;
                    taskRepository.Update(task);
                }
            }

            return(OnGet(id));
        }