public async Task <GenericResponseDTO <int> > UpdateUserProfile(ProfileUpdateDTO profileUpdateInfo) { int currentUserID; try { currentUserID = authHelper.GetCurrentUserId(User); } catch (System.NullReferenceException) { return(new GenericResponseDTO <int> { Message = "Not logged in.", Success = false }); } User currentUser = await database.Users .AsQueryable() .FirstOrDefaultAsync(user => user.Id == currentUserID); currentUser.FirstName = profileUpdateInfo.FirstName; currentUser.LastName = profileUpdateInfo.LastName; await database.SaveChangesAsync(); return(new GenericResponseDTO <int> { Success = true, Data = currentUser.Id }); }
public async Task <ResultMessage <StudentDTO> > EditStudentProfile(int id, ProfileUpdateDTO profile) { StudentDTO stud = await _studentService.GetSingleOrDefault(s => s.StudentId == id); if (profile.Photo != null) { ResultMessage <string> result = await _imgService.SaveProfileImage(profile.Photo); if (result.IsSuccess) { stud.Photo = result.Result; stud.PhotoVersion++; } } stud.Username = profile.Username; if (!string.IsNullOrEmpty(profile.Description)) { stud.Description = profile.Description; } return(await _studentService.Update(stud)); }