public DoneTask TrySaveDoneTask(DoneTaskVM doneTaskVM, IEnumerable <HttpPostedFileBase> files)
        {
            bool     isNew = false;
            DoneTask task  = _unitOfWork.TaskRepository.GetDoneTask(doneTaskVM.Id);

            if (task == null)
            {
                task  = new DoneTask();
                isNew = true;
            }

            task.Text      = doneTaskVM.Text;
            task.TaskId    = doneTaskVM.TaskId;
            task.StudentId = _unitOfWork.UserRepository.GetActualUserById <Student>(UserId).Id;
            task.Mark      = doneTaskVM.Mark;
            task.Comment   = doneTaskVM.Comment;
            task.Finished  = doneTaskVM.Finished;
            if (isNew)
            {
                _unitOfWork.TaskRepository.AddDoneTask(task);
            }
            _unitOfWork.SaveChanges();

            _fileService.SaveDoneTaskFiles(task.TaskId, task.Id, files);

            return(task);
        }
        public bool TryChangeDoneTask(DoneTaskVM doneTaskVM)
        {
            DoneTask doneTask = _unitOfWork.TaskRepository.GetDoneTask(doneTaskVM.Id);

            if (!doneTaskVM.Finished && String.IsNullOrWhiteSpace(doneTaskVM.Comment))
            {
                return(false);
            }
            else
            {
                doneTask.Mark     = doneTaskVM.Mark;
                doneTask.Finished = doneTaskVM.Finished;
                doneTask.Comment  = doneTaskVM.Comment;
                _unitOfWork.SaveChanges();
                return(true);
            }
        }
		public ActionResult DoneTask(DoneTaskVM doneTaskVM, string save, string saveEdit)
		{
			if (!String.IsNullOrWhiteSpace(save))
			{
				doneTaskVM.Finished = true;
			}
			else
			{
				doneTaskVM.Finished = false;
			}
			if (_subjectService.TryChangeDoneTask(doneTaskVM))
			{
				return RedirectToAction("Task", new { id = doneTaskVM.TaskId });
			}
			else
			{
				doneTaskVM = Mapper.Map<DoneTaskVM>(_subjectService.GetDoneTask(doneTaskVM.Id));
				ModelState.AddModelError("validValues", "Прокоментуйте, будь ласка");
				return View(doneTaskVM);
			}
		}
		public ActionResult SolveTask(int taskId)
		{
			DoneTask doneTask = _subjectService.GetDoneTaskByTaskId(taskId);
			if (doneTask != null && (!doneTask.Finished))
			{
				DoneTaskVM doneTaskVM = Mapper.Map<DoneTaskVM>(doneTask);
				return View(doneTaskVM);
			}
			else if (doneTask != null && (doneTask.Finished))
			{
				return RedirectToAction("DoneTask", new { doneTaskId = doneTask.Id });
			}
			else
			{ 
				DoneTaskVM doneTaskVM = new DoneTaskVM();
				doneTaskVM.TaskId = taskId;
				Task task = _subjectService.GetTaskById(taskId);
				doneTaskVM.Task = task;
				return View(doneTaskVM);
			}
		}
		public ActionResult DoneTask(int doneTaskId)
		{
			DoneTaskVM doneTaskVM = Mapper.Map<DoneTaskVM>(_subjectService.GetDoneTask(doneTaskId));
			return View(doneTaskVM);
		}
		public ActionResult SolveTask(IEnumerable<HttpPostedFileBase> files, DoneTaskVM doneTaskVM)
		{
			DoneTask task = _subjectService.GetDoneTask( _subjectService.TrySaveDoneTask(doneTaskVM, files).Id);
			return RedirectToAction("Task", new { id = task.TaskId });
		}