public async Task <ActionResult> ReturnFileFromHomework(ReturnFileForHomeworkDTO returnForHomework) { string token = HttpContext.Request.Headers["Authorization"]; token = token.Replace("Bearer ", string.Empty); var id = _tokenHelper.GetIdByToken(token); var subject = await _apiHelper.ReturnSubjectBySubjectID(returnForHomework.ClassID, returnForHomework.SubjectID); if (subject == null) { error.Err = "Nieprawidlowe ID klasy lub przedmiotu"; error.Desc = "Wprowadz poprawne wartosci"; return(NotFound(error)); } if (!subject.homeworks.Contains(returnForHomework.HomeworkID) && subject.teacherID != id) { error.Err = "Nieprawidlowe ID przedmiotu lub nie jestes nauczycielem"; error.Desc = "Wprowadz poprawne wartosci"; return(NotFound(error)); } var file = await _apiHelper.ReturnHomeworkFileBySenderID(returnForHomework.ClassID, returnForHomework.FileID); string asciiEquivalents = Encoding.ASCII.GetString(Encoding.GetEncoding(0).GetBytes(file.FileName)); Response.Headers.Add("fileName", asciiEquivalents); Response.Headers.Remove("Access-Control-Expose-Headers"); Response.Headers.Add("Access-Control-Expose-Headers", "*"); return(new FileStreamResult(file.Stream, file.ContentType)); }
public async Task <ActionResult <ReturnPrivateNoteDTO> > AddPrivateNote(AddPrivateNoteDTO addPrivateNoteDTO) { var id = _tokenHelper.GetIdByToken(HttpContext.Request.Headers["Authorization"]); var note = await _apiHelper.AddPrivateNote(addPrivateNoteDTO.Message, id); return(_mapper.Map <ReturnPrivateNoteDTO>(note)); }
public async Task <IActionResult> LoginViaToken() { string token = HttpContext.Request.Headers["Authorization"]; token = token.Replace("Bearer ", string.Empty); var id = _tokenHelper.GetIdByToken(token); var user = await _apiHelper.ReturnUserByID(id); if (user == null) { error.Err = "Nie znaleziono takiego uzytkownika"; error.Desc = "Wprowadz dane jeszcze raz"; return(StatusCode(405, error)); } var classes = new List <ClassToReturn>(); for (int i = 0; i < user.classMember.Count; i++) { var classObj = await _apiHelper.ReturnClassByID(user.classMember[i]); classes.Add(await _apiHelper.ReturnClassToReturn(classObj, id)); } var userToReturn = _apiHelper.ReturnUserToReturn(user); return(Ok(new { userToReturn, classes })); }
public async Task <IActionResult> ReturnNamesFromClass(ReturnNamesForClassDTO returnNames) { string token = HttpContext.Request.Headers["Authorization"]; token = token.Replace("Bearer ", string.Empty); var id = _tokenHelper.GetIdByToken(token); var classObj = await _apiHelper.ReturnClassByID(returnNames.ClassID); if (classObj == null) { error.Err = "Złe ID klasy"; error.Desc = "Wprowadź poprawne ID klasy"; return(StatusCode(405, error)); } if (!classObj.members.Contains(id)) { error.Err = "Nie należysz do klasy"; error.Desc = "Nie możesz sprawdzić imion i nazwisk"; return(StatusCode(405, error)); } var names = await _apiHelper.ReturnNames(classObj); UsersList users = new UsersList { Users = names }; return(Ok(users)); }
public async Task <IActionResult> PutMark([FromBody] PutMarkDTO putMark) { string token = HttpContext.Request.Headers["Authorization"]; token = token.Replace("Bearer ", string.Empty); var id = _tokenHelper.GetIdByToken(token); var subject = await _apiHelper.ReturnSubjectBySubjectID(putMark.ClassID, putMark.SubjectID); if (subject == null) { error.Err = "Nie jesteś nauczycielem przedmiotu"; error.Desc = "Nie możesz ocenić zadania"; return(StatusCode(405, error)); } if (!subject.homeworks.Contains(putMark.HomeworkID)) { error.Err = "Niepoprawne ID zadania"; error.Desc = "Wprowadz zadanie ponownie"; return(StatusCode(405, error)); } var response = await _apiHelper.PutMark(putMark.HomeworkID, putMark.ResponseID, putMark.Mark); if (response == null) { error.Err = "Niepoprawne ID odpowiedzi"; error.Desc = "Wprowadz ID odpowiedzi ponownie"; return(StatusCode(405, error)); } return(Ok(response)); }
public async Task <ActionResult <ReturnFamilyDTO> > CreateFamily(CreateFamilyDTO createFamilyDTO) { var id = _tokenHelper.GetIdByToken(HttpContext.Request.Headers["Authorization"]); var family = await _apiHelper.CreateFamily(id, createFamilyDTO.FamilyName); if (family == null) { return(BadRequest(new { errors = "Nie możesz stworzyć rodziny jako normalny użytkownik." })); } var familyToReturn = await _apiHelper.ReturnFamilyInfo(family.Id, id); return(familyToReturn); }
public async Task <IActionResult> SendMessage(SendMessageDTO sendMessage) { #region TokenValidation try { token = HttpContext.Request.Headers["Authorization"]; token = token.Replace("Bearer ", ""); if (!_tokenHelper.IsValidateToken(token)) { error.Err = "Token wygasł"; error.Desc = "Zaloguj się od nowa"; return(StatusCode(405, error)); } } catch { error.Err = "Nieprawidlowy token"; error.Desc = "Wprowadz token jeszcze raz"; return(StatusCode(405, error)); } #endregion var id = _tokenHelper.GetIdByToken(token); var user = await _apiHelper.ReturnUserByID(id); var classObj = await _apiHelper.ReturnClassByID(sendMessage.classID); if (classObj == null || !classObj.members.Contains(id)) { error.Err = "Nie możesz wysłać wiadomości"; error.Desc = "Nie należysz do tej klasy"; return(StatusCode(405, error)); } TextMessage textMessage = new TextMessage { messageID = 0, msessage = sendMessage.message, senderName = user.name, senderSurname = user.surrname, sendTime = DateTime.Now }; var message = await _apiHelper.SendMessage(sendMessage.subjectID, textMessage); return(Ok(textMessage)); }
public async Task <ActionResult <UserInfoDTO> > UpdateUserInfo([FromBody] UpdateUserInfoDTO updateUserInfoDTO) { var id = _tokenHelper.GetIdByToken(HttpContext.Request.Headers["Authorization"]); var user = await _apiHelper.UpdateUserInfo(id, updateUserInfoDTO.FirstName, updateUserInfoDTO.Surname); var mappedUser = _mapper.Map <UserInfoDTO>(user); return(mappedUser); }
public async Task <IActionResult> CreateClass(ClassToCreateDTO classToCreate) { string token = HttpContext.Request.Headers["Authorization"]; token = token.Replace("Bearer ", string.Empty); if (String.IsNullOrWhiteSpace(classToCreate.ClassName) || String.IsNullOrWhiteSpace(classToCreate.SchoolName)) { error.Err = "Uzupełnij wszystkie pola"; error.Desc = "Żadne z pól nie może zostać puste"; return(StatusCode(405, error)); } User creator = new User(); List <string> list1 = new List <string>(); var id = _tokenHelper.GetIdByToken(token); creator = await _apiHelper.ReturnUserByID(id); if (creator == null) { error.Err = "Nieprawidlowy token"; error.Desc = "Wprowadz token jeszcze raz"; return(StatusCode(405, error)); } if (creator.userRole == 1) { var createdClass = await _apiHelper.CreateClass(creator, classToCreate.ClassName, classToCreate.SchoolName); return(Ok(createdClass)); } else { error.Err = "Nie jestes nauczycielem"; error.Desc = "Nie mozesz zalozyc klasy"; return(StatusCode(409, error)); } }
public async Task <IActionResult> CreateQuiz(CreateQuizDTO createQuiz) { string token = HttpContext.Request.Headers["Authorization"]; token = token.Replace("Bearer ", string.Empty); var id = _tokenHelper.GetIdByToken(token); var subject = await _apiHelper.ReturnSubjectBySubjectID(createQuiz.classID, createQuiz.subjectID); if (subject == null) { error.Err = "Nie znaleziono przedmiotu w klasie o podanym ID."; error.Desc = "Wprowadź poprawne wartości ID dla klasy i przedmiotu."; return(NotFound(error)); } if (subject.teacherID != id) { error.Err = "Nie jesteś nauczycielem tego przedmiotu."; error.Desc = "Nie możesz dodać quizu."; return(NotFound(error)); } if (DateTime.Compare(createQuiz.FinishDate, DateTime.Now) < 0) { error.Err = "Data końcowa jest wcześniejsza jak obecna."; error.Desc = "Nie możesz dodać quizu."; return(NotFound(error)); } var isQuizAdded = await _apiHelper.IsQuizAdded(createQuiz); return(Ok(isQuizAdded)); }
public async Task <IActionResult> CreateSubject(CreateSubjectDTO createSubjectDTO) { string token = HttpContext.Request.Headers["Authorization"]; token = token.Replace("Bearer ", string.Empty); var id = _tokenHelper.GetIdByToken(token); var user = await _apiHelper.ReturnUserByMail(createSubjectDTO.UserToAddEmail); if (user == null || user.userRole == 0) { error.Err = "Nie poprawny nauczyciel"; error.Desc = "Wprowadz email nauczyciela jeszcze raz"; return(StatusCode(405, error)); } var classObj = await _apiHelper.ReturnClassByID(createSubjectDTO.ClassID); if (classObj == null) { error.Err = "Nie ma takiej klasy"; error.Desc = "Wprowadź ID klasy jeszcze raz"; return(StatusCode(405, error)); } if (classObj.creatorID != id) { error.Err = "Nie jestes wychowawcą"; error.Desc = "Nie możesz tworzyć przedmiotu"; return(StatusCode(405, error)); } var subject = await _apiHelper.AddSubjectToClass(user.Id, classObj, createSubjectDTO.SubjectName); await _apiHelper.ReplaceClassInfo(subject.ClassObj); return(Ok(subject)); }
public async Task <IActionResult> AddHomeworkToSubject(HomeworkToAddDTO homeworkToAdd) { string token = HttpContext.Request.Headers["Authorization"]; token = token.Replace("Bearer ", string.Empty); var id = _tokenHelper.GetIdByToken(token); var classObj = await _apiHelper.ReturnClassByID(homeworkToAdd.ClassID); var subject = await _apiHelper.ReturnSubjectBySubjectID(homeworkToAdd.ClassID, homeworkToAdd.SubjectID); if (subject == null || subject.teacherID != id || classObj == null) { error.Err = "Nie jestes nauczycielem tej klasy"; error.Desc = "Nie mozesz dodac zadania"; return(StatusCode(405, error)); } try { var homework = await _apiHelper.AddHomeworkToSubject(subject, homeworkToAdd.Name, homeworkToAdd.Description, homeworkToAdd.Time, homeworkToAdd.FilesID, homeworkToAdd.LinkHrefs); if (homework == null) { error.Err = "Złe ID pliku"; error.Desc = "Nie mozesz dodac zadania"; return(StatusCode(405, error)); } return(Ok(homework)); } catch { error.Err = "Błędne dane"; error.Desc = "Nie mozesz dodac zadania"; return(StatusCode(405, error)); } }
public async Task <ActionResult <ReturnCalendarNoteDTO> > AddCalendarNote(AddCalendarNoteDTO addCalendarNoteDTO) { var id = _tokenHelper.GetIdByToken(HttpContext.Request.Headers["Authorization"]); var mappedNote = _mapper.Map <CalendarNote>(addCalendarNoteDTO); var calendarNote = await _apiHelper.AddCalendarNote(mappedNote, id); if (calendarNote == null) { return(BadRequest(new { errors = "Niepoprawne id rodziny." })); } return(_mapper.Map <ReturnCalendarNoteDTO>(calendarNote)); }