public async Task <IActionResult> CreateSchool([FromForm] SchoolForCreateDto schoolForCreateDto) { if (schoolForCreateDto.Logo != null && !filesUploader.IsValidExtension(schoolForCreateDto.Logo.FileName, PhotoExtensions)) { return(BadRequest("Logo posiada niepoprawny format")); } int currentUserId = int.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); var currentUser = await database.UserRepository.Get <User>(currentUserId); var school = mapper.Map <School>(schoolForCreateDto); if (currentUser.Rental != null) { school.SetRental(currentUser.Rental); } if (await schoolService.CreateSchool(school, currentUserId)) { await SetLogoUrl(schoolForCreateDto.Logo, school); await notificationSystem.PushNotification(currentUserId, StaticExpressions.SchoolCreated(school.Name)); await notificationSystem.PushNotificationToUsersByRoles(StaticExpressions.SchoolCreated(school.Owner.UserName, school.Name, school.Id), RolesPermitted, NotificationType.School); var schoolToReturn = mapper.Map <SchoolDetailsDto>(school); return(Ok(schoolToReturn)); } return(BadRequest("Dodawanie szkółki nie powiodło się")); }
public async Task <IActionResult> SetPhoto(int id, [FromForm] UserToSetPhotoDto userToSetPhotoDto) { var user = await accountManager.GetUser(id); if (!filesUploader.IsValidExtension(userToSetPhotoDto.Photo.FileName, new string[] { ".img", ".jpg", ".png" })) { return(BadRequest("Niepoprawny format zdjęcia")); } string photoUrl = await GeneratePhotoUrl(id, userToSetPhotoDto); if (await accountManager.SetPhoto(user, photoUrl)) { return(NoContent()); } throw new AccountException("Wystąpił błąd podczas zmiany zdjęcia"); }