public async Task <ThesisDTO> CreateThesisIfNeeded(string professorId) { try { ThesisDTO exists = await _context.Theses .Where(t => t.Professor.Id == professorId && t.Title == null) .Include(t => t.Professor) .FirstOrDefaultAsync(); if (exists != null) { return(exists); } FacultyProfessor prof = new FacultyProfessor { Id = professorId }; _context.Attach(prof); Thesis newThesis = new Thesis { Professor = prof, DateCreated = DateTime.Now }; _context.Theses.Add(newThesis); await _context.SaveChangesAsync(); return(newThesis); } catch (Exception ex) { _logger.LogError(ex.Message); return(null); } }
public static FacultyProfessorDTO CastWithoutLists(FacultyProfessor prof) { if (prof == null) { return(null); } return(new FacultyProfessorDTO { Id = prof.Id, FullName = prof.FullName, Email = prof.Email, Office = prof.Office, ProfileImageUrl = prof.ProfileImageUrl, Role = "Professor" }); }
public async Task <IdentityResult> RegisterProfessor(RegistrationDTO userInfo) { FunctionReturnDTO uploadResult = null; if (userInfo.ProfileImage != null) { uploadResult = await UploadImage(userInfo.Email, userInfo.ProfileImage); if (!uploadResult.Success) { return(IdentityResult.Failed(new IdentityError[] { new IdentityError { Code = "Upload error", Description = uploadResult.Result } })); } } FacultyProfessor facultyProfessor = new FacultyProfessor { FullName = userInfo.FullName, Email = userInfo.Email, UserName = userInfo.Email, ProfileImageUrl = uploadResult == null ? null : uploadResult.Result, Office = userInfo.Office }; IdentityResult result = await _userManager.CreateAsync(facultyProfessor, userInfo.Password); if (!result.Succeeded) { return(result); } await _userManager.AddToRoleAsync(facultyProfessor, "Professor"); return(result); }