public async Task <ActionResult> CreateStudent([FromBody] StudentRegisterDTO newStudent) { newStudent.Password = AuthentificationService.EncryptPassword(newStudent.Password); string base64Image = newStudent.Student.ProfilePicturePath; if (!string.IsNullOrEmpty(base64Image)) { string imageFileId = await _sharedRepository.GetNextImageId(); newStudent.Student.ProfilePicturePath = FileManagerService.SaveImageToFile(base64Image, imageFileId); } if (await _repository.CreateNonExistingStudent(newStudent)) { StudentDTO student = await _repository.StudentExists(newStudent.Student.Email); student.Student.ProfilePicturePath = base64Image; string token = JwtManager.GenerateJWToken(student.Student, student.Id.ToString()); return(Ok(new JsonResult(token))); } else { return(Ok(new JsonResult("Email taken"))); } }
public async Task <ActionResult> CreateGroup(int ownerId, Group newGroup) { string imageFileId = await _sharedRepository.GetNextImageId(); newGroup.GroupPicturePath = FileManagerService.SaveImageToFile(newGroup.GroupPicturePath, imageFileId); await _repository.CreateGroup(ownerId, newGroup); return(Ok()); }
public async Task <ActionResult> PictureListNewsEdit(string newsId, [FromBody] PictureNewsEditDTO editValue) { if (!string.IsNullOrEmpty(editValue.Picture)) { editValue.Picture = FileManagerService.SaveImageToFile(editValue.Picture, "mainPicture" + newsId); } await _repository.EditNews(newsId, editValue); return(Ok()); }
public async Task <ActionResult> AddNews(string editorId, [FromBody] News news) { string tempNewsMainPicture = null; List <Paragraph> tempNewsParagraphs = null; if (!string.IsNullOrEmpty(news.MainPicturePath)) { tempNewsMainPicture = news.MainPicturePath; news.MainPicturePath = null; } foreach (Paragraph p in news.Paragraphs) { if (!string.IsNullOrEmpty(p.PicturePath)) { tempNewsParagraphs = news.Paragraphs; news.Paragraphs = null; break; } } string newsId = await _repository.AddNews(news); if (!string.IsNullOrEmpty(tempNewsMainPicture) || tempNewsParagraphs != null) { if (!string.IsNullOrEmpty(tempNewsMainPicture)) { news.MainPicturePath = FileManagerService.SaveImageToFile(tempNewsMainPicture, "mainPicture" + news.Id); } if (tempNewsParagraphs != null) { int i = 0; news.Paragraphs = tempNewsParagraphs; foreach (Paragraph p in tempNewsParagraphs) { if (!string.IsNullOrEmpty(p.PicturePath)) { news.Paragraphs.ElementAt(i).PicturePath = FileManagerService.SaveImageToFile(p.PicturePath, "paragraphPicture" + i + news.Id); } i++; } } await _repository.AddNewsPictures(newsId, news.MainPicturePath, news.Paragraphs); } if (newsId != null && newsId != "") { await _editorRepository.AddNews(editorId, newsId); } return(Ok()); }
public async Task <ActionResult> UpdateStudent(int studentId, [FromBody] Student updatedStudent) { bool res = await _repository.StudentExists(studentId); if (!res) { return(BadRequest("Student doesnt exist!")); } string imageFileId = await _sharedRepository.GetNextImageId(); updatedStudent.ProfilePicturePath = FileManagerService.SaveImageToFile(updatedStudent.ProfilePicturePath, imageFileId); await _repository.UpdateStudent(studentId, updatedStudent); return(Ok(updatedStudent)); }
public async Task <ActionResult> ParagraphListNewsEdit(string newsId, [FromBody] ParagraphListEditDTO editValue) { int i = 0; foreach (Paragraph p in editValue.Paragraphs) { if (!string.IsNullOrEmpty(p.PicturePath)) { p.PicturePath = FileManagerService.SaveImageToFile(p.PicturePath, "paragraphPicture" + i + newsId); } i++; } await _repository.EditNews(newsId, editValue); return(Ok()); }
public async Task <ActionResult> UpdateGroup(int groupId, Group newGroup) { bool res = await _repository.GroupExists(groupId); if (!res) { return(BadRequest("Group doesnt exist!")); } string imageFileId = await _sharedRepository.GetNextImageId(); newGroup.GroupPicturePath = FileManagerService.SaveImageToFile(newGroup.GroupPicturePath, imageFileId); await _repository.UpdateGroup(groupId, newGroup); return(Ok()); }