public async Task <bool> Consume(string message) { ProfileEvent profileEvent = JsonConvert.DeserializeObject <ProfileEvent>(message); if (profileEvent == null) { return(false); } Domain.Entities.Profile profile = await _context.Profiles.FindAsync(profileEvent.Id); if (profile == null) { Domain.Entities.Profile newProfile = new Domain.Entities.Profile { Id = profileEvent.Id, DisplayName = profileEvent.DisplayName, Avatar = profileEvent.Avatar }; _context.Profiles.Add(newProfile); return(await _context.SaveChangesAsync() > 0); } return(false); }
public async Task UpdateProfile(UserRegisterDto userRegisterDto) { var UserId = Convert.ToInt32(_context.HttpContext.User.Claims.Where(x => x.Type == "UserId").First().Value); var userProfile = await _profileRepository.GetAuthUserProfile(UserId); Domain.Entities.Profile profile = new Domain.Entities.Profile(); IFormFile file = userRegisterDto.Image; string fullPath = null; var imageId = 0; if (file != null) { string folderName = "Upload"; string webRootPath = _hostingEnvironment.WebRootPath; if (string.IsNullOrWhiteSpace(webRootPath)) { webRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); } string newPath = Path.Combine(webRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); fullPath = Path.Combine(newPath, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } } imageId = _serviceImage.GetIdInsertedImage(fullPath); userProfile.ImageId = imageId; } userProfile.FirstName = userRegisterDto.FirstName; userProfile.LastName = userRegisterDto.LastName; userProfile.PhoneNumber = userRegisterDto.PhoneNumber; userProfile.DateOfBirth = userRegisterDto.DateOfBirth; userProfile.Email = userProfile.Email; await _profileRepository.UpdateProfile(userProfile); }
public async Task <GetProfileDto> Handle(CreateProfileCommand request, CancellationToken cancellationToken) { var entity = new Domain.Entities.Profile { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email, PhoneNumber = request.PhoneNumber, WebSite = request.WebSite }; await _dbContext.Profiles.AddAsync(entity, cancellationToken); await _dbContext.SaveChangesAsync(cancellationToken); return(_mapper.Map <GetProfileDto>(entity)); }
public async Task <bool> Consume(string message) { FollowEvent followEvent = JsonConvert.DeserializeObject <FollowEvent>(message); Domain.Entities.Profile profile = await _context.Profiles.FindAsync(followEvent.ProfileId); Domain.Entities.Profile follower = await _context.Profiles.FindAsync(followEvent.FollowerId); Domain.Entities.Follow follow = await _context.Follows.FirstOrDefaultAsync(x => x.Profile == profile && x.Follower == follower); if (follow != null) { _context.Follows.Remove(follow); return(await _context.SaveChangesAsync() > 0); } return(false); }
public async Task <bool> Consume(string message) { ProfileEvent profileEvent = JsonConvert.DeserializeObject <ProfileEvent>(message); if (profileEvent == null) { return(false); } Domain.Entities.Profile profile = await _context.Profile.FindAsync(profileEvent.Id); if (profile != null) { profile.Avatar = profileEvent.Avatar; profile.DisplayName = profileEvent.DisplayName; _context.Profile.Update(profile); return(await _context.SaveChangesAsync() > 0); } return(false); }
public IActionResult Post(ProfileDto profileDto) { try { var tools = new SixTools(_httpContextAccessor); var user = _userService.GetById(tools.GetUserTokenId()); if (user == null) { return(BadRequest(new { StatusCode = HttpStatusCode.BadRequest, message = "Usuário não localizado" })); } if (!user.Profile.Create) { return(BadRequest(new { StatusCode = HttpStatusCode.BadRequest, message = "Usuário não possui permissão para realizar esta operacao" })); } var profile = new Domain.Entities.Profile(name: profileDto.Name, create: profileDto.Create, update: profileDto.Update, delete: profileDto.Delete, isAdmin: profileDto.IsAdmin); _profileService.Post(profile); return(Ok(_mapper.Map <ProfileDto>(profile))); } catch (Exception e) { return(BadRequest(new { StatusCode = HttpStatusCode.PreconditionFailed, message = e.Message })); } }
public Domain.Entities.Profile Update(Domain.Entities.Profile objectInstance) { return(_ProfileRepository.Update(objectInstance)); }
public Domain.Entities.Profile Post(Domain.Entities.Profile objectInstance) { return(_ProfileRepository.Post(objectInstance)); }
public async Task <IActionResult> AddUser() { UserRegisterDto userRegisterDto = new UserRegisterDto(); JobSolution.Domain.Entities.Profile userProfile = new Domain.Entities.Profile(); try { foreach (var key in _context.HttpContext.Request.Form.Keys) { userRegisterDto = JsonConvert.DeserializeObject <UserRegisterDto>(_context.HttpContext.Request.Form[key]); var file = _context.HttpContext.Request.Form.Files.Count > 0 ? _context.HttpContext.Request.Form.Files[0] : null; if (file != null) { string folderName = "Profile"; string webRootPath = _hostingEnvironment.WebRootPath; if (string.IsNullOrWhiteSpace(webRootPath)) { webRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); } string newPath = Path.Combine(webRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); string fullPath = Path.Combine(newPath, fileName); userProfile.ImagePath = fullPath; using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } } } } } catch (Exception e) { } if (userRegisterDto == null) { return(new StatusCodeResult(500)); } var findExistedProfile = await _userManager.FindByEmailAsync(userRegisterDto.Email); if (findExistedProfile != null) { return(new BadRequestObjectResult("Email or username exist!")); } var CreateUserToAdd = new User() { SecurityStamp = Guid.NewGuid().ToString(), UserName = userRegisterDto.UserName, Email = userRegisterDto.Email }; await _userManager.CreateAsync(CreateUserToAdd, userRegisterDto.Password); await _userManager.AddToRoleAsync(CreateUserToAdd, userRegisterDto.RoleFromRegister); var AddUser = new User() { SecurityStamp = Guid.NewGuid().ToString(), UserName = userRegisterDto.UserName, Email = userRegisterDto.Email }; var Profile = new JobSolution.Domain.Entities.Profile { FirstName = userRegisterDto.FirstName, LastName = userRegisterDto.LastName, Email = userRegisterDto.Email, PhoneNumber = userRegisterDto.PhoneNumber, University = userRegisterDto.University, UserId = _userManager.FindByEmailAsync(AddUser.Email).Result.Id, }; _dbContext.Profiles.Add(Profile); _dbContext.SaveChanges(); var signinCredentials = new SigningCredentials(_authOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256); var jwtSecurityToken = new JwtSecurityToken( issuer: _authOptions.Issuer, audience: _authOptions.Audience, claims: new List <Claim>() { new Claim(ClaimTypes.Role, userRegisterDto.RoleFromRegister), new Claim(ClaimTypes.NameIdentifier, Profile.UserId.ToString()) }, expires: DateTime.Now.AddDays(30), signingCredentials: signinCredentials); var tokenHandler = new JwtSecurityTokenHandler(); var encodedToken = tokenHandler.WriteToken(jwtSecurityToken); return(new OkObjectResult(new { AccessToken = encodedToken })); }
public async Task UpdateProfile() { ProfileDTO profileDTO = new ProfileDTO(); JobSolution.Domain.Entities.Profile userProfile = new Domain.Entities.Profile(); }