public async Task <UniversityCreationResultDTO> CreateUniversityAsync(UniversityCreateRequestViewDTO createRequestDTO) { var university = new University { Name = createRequestDTO.UniversityName, }; await universityRepository.AddAsync(university); await universityRepository.SaveChangesAsync(); UniversityAdminRegistrationDTO adminRegisterRequest = new UniversityAdminRegistrationDTO { FirstName = createRequestDTO.SubmitterFirstName, LastName = createRequestDTO.SubmitterLastName, Email = createRequestDTO.Email, Password = passwordGenerator.GeneratePassword(), UniversityId = university.Id }; await authService.RegisterUniversityAdminAsync(adminRegisterRequest); return(new UniversityCreationResultDTO { UniversityId = university.Id, UniversityName = university.Name, AdminEmail = adminRegisterRequest.Email, AdminPassword = adminRegisterRequest.Password }); }
public async Task AddAsync(string name, string shortcut, string place, string base64Image) { var univeristy = await _universityRepository.GetByNameAsync(name); if (univeristy != null) { throw new OcenUczelnieException(ErrorCodes.NameOccupied); } string imageUrl = await _storageService.UploadImageAndReturnUrlAsync(base64Image, name); univeristy = new University(Guid.NewGuid(), name, shortcut, place, imageUrl); await _universityRepository.AddAsync(univeristy); }
public async Task <ActionResult> Create(IFormCollection collection, University university) { try { await universityRepository.AddAsync(university); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <UniversityResponse> SaveAsync(University university) { try { await _universityRepository.AddAsync(university); await _unitOfWork.CompleteAsync(); return(new UniversityResponse(university)); } catch (Exception e) { return(new UniversityResponse($"An error ocurred while saving the university: {e.Message}")); } }
public async Task <ResponseModel <UniversityResource> > SaveAsync(University university) { try { var existingCity = await cityRepository.FindByIdAsync(university.CityId); if (existingCity == null) { return new ResponseModel <UniversityResource>() { Success = false, Message = "Invalid city." } } ; await universityRepository.AddAsync(university); await unitOfWork.CompleteAsync(); var universityResource = mapper.Map <University, UniversityResource>(university); return(new ResponseModel <UniversityResource>() { Success = true, Data = universityResource, Message = "Successfully added!" }); } catch (Exception ex) { return(new ResponseModel <UniversityResource>() { Success = false, Message = $"An error occurred when saving the university: { ex.Message}" }); } }