public bool JustifyStudentAbsence(string id, string week) { var student = _repository.FindOne(Convert.ToInt32(id)); if (student == null) { throw new KeyNotFoundException(nameof(id) + ' ' + id); } var updatedStudent = EntityUtils.Clone <Student, int>(student); updatedStudent.JustifiedAbsences |= 1 << (Convert.ToInt32(week) - 1); return(_repository.Update(updatedStudent) == null); }
public bool MarkStudentAbsent(string id, string week) { if (string.IsNullOrEmpty(week)) { week = _weekUtils.GetCurrentDidacticWeek().ToString(); } if (Convert.ToInt32(week) > _weekUtils.GetCurrentDidacticWeek()) { throw new ArgumentOutOfRangeException(nameof(week) + ' ' + week); } var student = _repository.FindOne(Convert.ToInt32(id)); if (student == null) { throw new KeyNotFoundException(nameof(id) + ' ' + id); } var updatedStudent = EntityUtils.Clone <Student, int>(student); updatedStudent.Absences |= 1 << (Convert.ToInt32(week) - 1); return(_repository.Update(updatedStudent) == null); }
public bool ExtendTaskDeadline(string id, string newDeadlineWeek) { var task = _repository.FindOne(Convert.ToInt32(id)); if (task == null) { throw new KeyNotFoundException(nameof(id) + ' ' + id); } if (task.DeadlineWeek < _weekUtils.GetCurrentDidacticWeek()) { throw new InvalidOperationException("Task is finished"); } if (Convert.ToInt32(newDeadlineWeek) < _weekUtils.GetCurrentDidacticWeek()) { throw new InvalidOperationException("New deadline is before current week"); } var updatedTask = EntityUtils.Clone <Task, int>(task); updatedTask.DeadlineWeek = Convert.ToInt32(newDeadlineWeek); return(_repository.Update(updatedTask) == null); }