public async Task <ActionResult> UpdateUser(MemberUpdateDto memberUpdateDto) { var user = await _unitOfWork.UserRepository.GetUserByNameAsync(User.GetUserName()); _mapper.Map(memberUpdateDto, user); _unitOfWork.UserRepository.Update(user); if (await _unitOfWork.SaveChanges()) { return(NoContent()); } return(BadRequest("Failed to updated the profile")); }
public async Task <ActionResult <PhotoDto> > AddPhoto(IFormFile file) { var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUserName()); var result = await _photoService.AddPhotoAsync(file); if (result.Error != null) { return(BadRequest(result.Error.Message)); } var photo = new Photo { StudentUrl = null, LogoUrl = null }; if (user.AppUserType == "ColStudent") { photo.StudentUrl = result.SecureUrl.AbsoluteUri; photo.PublicId = result.PublicId; } ; if (user.AppUserType == "EmpHr") { photo.LogoUrl = result.SecureUrl.AbsoluteUri; photo.PublicId = result.PublicId; } ; if (user.Photos.Count == 0 && user.AppUserType == "ColStudent") { photo.IsMain = true; } if (user.Photos.Count == 0 && user.AppUserType == "EmpHr") { photo.IsMainLogo = true; } user.Photos.Add(photo); if (await _unitOfWork.Complete()) { // return _mapper.Map<PhotoDto>(photo); // return CreatedAtRoute("GetUser", _mapper.Map<PhotoDto>(photo)); return(CreatedAtRoute("GetUser", new { username = user.UserName }, _mapper.Map <PhotoDto>(photo))); // used 3rd overload which // has the following parameters: string routename, object routeValues, object value } return(BadRequest("Problem adding photo")); }
public async Task <ActionResult <IEnumerable <MessageDto> > > GetMessagesForUser([FromQuery] MessageParams messageParams) { messageParams.Username = User.GetUserName(); var messages = await _messageRepository.GetMessageForUser(messageParams); Response.AddPaginationHeader(messages.CurrentPage, messages.PageSize, messages.TotalCount, messages.TotalPages); return(messages); }
public async Task <ActionResult> UpdateUser(MemberUpdateDto memberUpdateDto) { var user = await _userRepository.GetUserByUsernameAsync(User.GetUserName()); _mapper.Map(memberUpdateDto, user); _userRepository.Update(user); if (await _userRepository.SaveAllAsync()) { return(NoContent()); } return(BadRequest("Failed to update user")); }
public async Task <ActionResult <IEnumerable <MessageDto> > > GetMessagesForUser([FromQuery] MessageParams messageParams) { messageParams.Username = User.GetUserName(); var messages = await _unitOfWork.MessageRepository.GetMessagesForUser(messageParams); //Custome Extention method for HttpResponse Response.AddPaginationHeader(messages.CurrentPage, messages.PageSize , messages.TotalCount, messages.TotalPages); return(Ok(messages)); }
public async Task <ActionResult> UpdateUser(MemberUpdateDTO memberInfo) { // var username = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var user = await UserRepo.GetUserByUserNameAsync(User.GetUserName()); _mapper.Map(memberInfo, user); UserRepo.UpdateUser(user); if (await UserRepo.SaveAllAsync()) { return(NoContent()); } return(BadRequest("Failed To Update User")); }
public async Task <ActionResult> UpdateUser(MemberUpdateDTO memberUpdateDTO) { var username = User.GetUserName(); //User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(username); _mapper.Map(memberUpdateDTO, user); _unitOfWork.UserRepository.Update(user); if (await _unitOfWork.Complete()) { return(NoContent()); } return(BadRequest("Failed to update user")); }
public async Task <ActionResult <IEnumerable <MemberDto> > > GetUsers([FromQuery] UserParams userParams) { var user = await _repo.GetByUsernameAsync(User.GetUserName()); userParams.CurrentUsername = user.UserName; var users = await _repo.GetMembersAsync(userParams); Response.AddPaginationHeader(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages); return(Ok(users)); }
public async Task <ActionResult> UpdateUser(MemberUpdateDto memberUpdateDto) { var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUserName()); _mapper.Map(memberUpdateDto, user); _unitOfWork.UserRepository.Update(user); if (await _unitOfWork.Complete()) { return(NoContent()); } return(BadRequest("User update failed")); }
public async Task <ActionResult <MemberDto> > GetUser(string username) { // var user = await _unitOfWork.UserRepository.GetUserByUserNameAsync(username); // var userToReturn = _mapper.Map<MemberDto>(user); // return userToReturn; var currentUsername = User.GetUserName(); return(await _unitOfWork.UserRepository.GetMemberByUserNameAsync(username, isCurrentUser : currentUsername == username)); }
public async Task <ActionResult <IEnumerable <MemberDto> > > GetUsers([FromQuery] UserParams userParams) { var gender = await _unitOfWork.UserRepository.GetUserGender(User.GetUserName()); userParams.CurrentUsername = User.GetUserName(); if (string.IsNullOrEmpty(userParams.Gender)) { userParams.Gender = gender == "male" ? "female" : "male"; } var users = await _unitOfWork.UserRepository.GetMembersAsync(userParams); Response.AddPaginationHeaders(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages); return(Ok(users)); }
public async Task <ActionResult <MemberDto> > PutUser(MemberUpdateDto memberUpdateDto) { var user = await _userRepository.GetUserByUserNameAsync(User.GetUserName()); _mapper.Map(memberUpdateDto, user); _userRepository.Update(user); if (!await _unitOfWork.Complete()) { return(BadRequest()); } return(_mapper.Map <MemberDto>(user)); }
public async Task <ActionResult> UpdateUser(MemberUpdateDTO memberUpdateDTO) { var username = User.GetUserName(); var user = await _userRepository.GetUserByUsernameAsync(username); _mapper.Map(memberUpdateDTO, user); if (await _userRepository.SaveAllAsync()) { return(NoContent()); } return(BadRequest("Profile not updated")); }
public async Task <ActionResult <IEnumerable <MemberDTO> > > GetUsers([FromQuery] UserParams userParams) { var user = await _userRepository.GetUserByUserNameAsync(User.GetUserName()); userParams.CurrentUserName = user.UserName; if (string.IsNullOrWhiteSpace(userParams.Gender)) { userParams.Gender = user.Gender == "male" ? "female" : "male"; } var users = await _userRepository.GetMembersAsync(userParams); Response.AddPaginationHeader(users.Current, users.PageSize, users.TotalCount, users.TotalPages); return(Ok(users)); }
public async Task <ActionResult <IEnumerable <MemberDto> > > GetUsers([FromQuery] UserParams userParams) { userParams.CurrentUsername = User.GetUserName(); if (string.IsNullOrEmpty(userParams.Gender)) { userParams.Gender = await _userRepository.GetUserGenderAsync(User.GetUserName()) == "female" ? "male" : "female"; } var users = await _userRepository.GetMembersAsync(userParams); Response.AddPaginationHeader <UserHeader, MemberDto, UserParams>(users, _mapper, userParams); return(Ok(users)); }
public async Task <ActionResult> UpdateUser(MemberUpdateDto memberUpdateDto) { // Function .GetUserName is extended in ClaimsPrincipleExtensions var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUserName()); _mapper.Map(memberUpdateDto, user); _unitOfWork.UserRepository.Update(user); if (await _unitOfWork.Complete()) { return(NoContent()); } return(BadRequest("Failed to update user")); }
public async Task <ActionResult> updateUser(MemberUpdateDto member) { //var username = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var username = User.GetUserName(); var user = await _userRepository.GetUserByUsernameAsync(username); _mapper.Map(member, user); _userRepository.Update(user); if (await _userRepository.SaveAllAsync()) { return(NoContent()); } return(BadRequest("Failed to update user")); }
public async Task <ActionResult> UpdateUser(MemberUpdateDTO memberUpdateDTO) { var user = await _userRepository.GetUserByUserNameAsync(User.GetUserName()); _mapper.Map(memberUpdateDTO, user); _userRepository.Update(user); if (await _userRepository.SaveAllChangesAsync()) { return(NoContent()); } else { return(BadRequest("Failure while updating the user")); } }
public async Task <ActionResult <PhotoDto> > AddPhoto(IFormFile file) { var result = await _unitOfWork.UserRepository.AddPhoto(file); if (_unitOfWork.HasChanges()) { await _unitOfWork.Complete(); } if (result is null) { return(BadRequest()); } return(CreatedAtRoute("GetUser", new { username = User.GetUserName() }, result)); //return CreatedAtRoute("GetUser", result); }
public async Task <ActionResult> UpdateUser(MemberUpdateDto memberUpdateDto) { var userName = User.GetUserName(); var user = await this.unitOfWork.UserRepository.GetUserByUserNameAsync(userName); this.mapper.Map(memberUpdateDto, user); this.unitOfWork.UserRepository.Update(user); if (await this.unitOfWork.Complete()) { return(NoContent()); } return(BadRequest("Failed to update user.")); }
public async Task <ActionResult> SetMainPhoto(int photoId) { var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUserName()); var photo = user.Photos.FirstOrDefault(x => x.Id == photoId); if (user.AppUserType == "ColStudent") { if (photo.IsMain) { return(BadRequest("This is already your main photo")); } var currentMain = user.Photos.FirstOrDefault(x => x.IsMain); if (currentMain != null) { currentMain.IsMain = false; photo.IsMain = true; } } if (user.AppUserType == "EmpHr") { if (photo.IsMain) { return(BadRequest("This is already your main logo")); } var currentMain = user.Photos.FirstOrDefault(x => x.IsMainLogo); if (currentMain != null) { currentMain.IsMainLogo = false; photo.IsMainLogo = true; } } if (await _unitOfWork.Complete()) { return(NoContent()); } return(BadRequest("Failed to set main photo")); }
public async Task <ActionResult> DeletePhoto(int photoId) { var username = User.GetUserName(); var user = await _context.Users .Include(c => c.Doctor.Photos) .FirstOrDefaultAsync(c => c.UserName == username); if (user.Doctor == null) { return(BadRequest("Invalid data!")); } var photo = user.Doctor.Photos.FirstOrDefault(x => x.Id == photoId); if (photo == null) { return(NotFound()); } if (photo.IsMain) { return(BadRequest("You cannot delete your main photo!")); } if (photo.PublicId != null) { var result = await _photoService.DeletePhotoAsync(photo.PublicId); if (result.Error != null) { return(BadRequest(result.Error.Message)); } } user.Doctor.Photos.Remove(photo); if (await _context.SaveChangesAsync() > 0) { return(Ok()); } return(BadRequest("Failed to delete the photo")); }
public async Task <ActionResult> UpdateUser(MemberUpdateDto memberUpdateDto) { //get user from token generation var username = User.GetUserName(); //get user object from database var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(username); _mapper.Map(memberUpdateDto, user); _unitOfWork.UserRepository.Update(user); if (await _unitOfWork.Complete()) { return(NoContent()); } return(BadRequest("Failed to update user")); }
public async Task <ActionResult> MakeAnAppoinment(MakeAnAppoinmentDto makeAnAppoinmentDto) { var userPacient = await _pacientRepository.GetPacientByUsername(User.GetUserName()); if (makeAnAppoinmentDto == null || makeAnAppoinmentDto.DoctorId == 0 || makeAnAppoinmentDto.DayUnixTime == 0 || makeAnAppoinmentDto.FromTimeSpan == 0 || makeAnAppoinmentDto.ToTimeSpan == 0 || userPacient.Pacient == null) { return(BadRequest("Parametrii invalizi!")); } if (await _appoinmentsRepository.AddAppoinmentAsync(makeAnAppoinmentDto, userPacient.Pacient.Id)) { return(Ok()); } return(BadRequest("Upps..ceva nu a mers!")); }
public async Task <ActionResult <MessageDto> > CreateMessage(CreateMessageDto messageDto) { if (String.IsNullOrEmpty(messageDto.Content)) { return(BadRequest("Message cannot be empty")); } //var senderId = User.GetUserId(); var senderUserName = User.GetUserName(); if (senderUserName == messageDto.RecipientUsername) { return(BadRequest("You cannot send messages to yourself")); } var sender = await _unitOfWork.UserRepository.GetUserByUserNameAsync(senderUserName); var recipient = await _unitOfWork.UserRepository.GetUserByUserNameAsync(messageDto.RecipientUsername); if (recipient == null) { return(NotFound("Recipient not found")); } var message = new Message() { Content = messageDto.Content, Sender = sender, SenderUsername = senderUserName, Recipient = recipient, RecipientUsername = recipient.UserName }; _unitOfWork.MessageRepository.AddMessage(message); if (await _unitOfWork.CompleteAsync()) { return(Ok(_mapper.Map <MessageDto>(message))); } return(BadRequest("Failed to send message")); }
public async Task <ActionResult> UpdateUser(MemberDto memberUpdateDto) { var user = await _userRepository.GetUserByUserNameAsync(User.GetUserName()); //_mapper.Map(memberUpdateDto, user); user.introduction = memberUpdateDto.introduction; user.LookingFor = memberUpdateDto.LookingFor; user.Interests = memberUpdateDto.Interests; user.Country = memberUpdateDto.Country; user.City = memberUpdateDto.City; _userRepository.Update(user); if (await _userRepository.SaveAllAsync()) { return(NoContent()); } return(BadRequest("Failed to update user")); }
public async Task <ActionResult> UpdateUser(MemberUpdateDto memberUpdateDto) { var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUserName()); if (user == null) { return(NotFound($"User with username {User.GetUserName()} was not found")); } _mapper.Map(memberUpdateDto, user); _unitOfWork.UserRepository.Update(user); if (await _unitOfWork.Complete()) { return(NoContent()); } return(BadRequest("Failed to update user")); }
public async Task <ActionResult> UpdateUser(MemberUpdateDto memberUpdateDto) { // /// This will give us the user's username from the token that the Api uses to authenticate this user. // /// and this is the user we're going to update // var = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; // var user = await _userRepository.GetUserByUsernameAsync(username); var user = await _userRepository.GetUserByUsernameAsync(User.GetUserName()); _mapper.Map(memberUpdateDto, user); _userRepository.Update(user); if (await _userRepository.SaveAllAsync()) { return(NoContent()); } return(BadRequest("Failed to update user.")); }
[HttpGet] // new get users after adding UserParams public async Task <ActionResult <IEnumerable <MemberDto> > > GetUsers([FromQuery] UserParams userParams) { var appUserType = await _unitOfWork.UserRepository.GetUserAppUserType(User.GetUserName()); userParams.CurrentUsername = User.GetUserName(); if (string.IsNullOrEmpty(userParams.AppUserType)) { userParams.AppUserType = appUserType == "ColStudent" ? "EmpHr" : "ColStudent"; } var users = await _unitOfWork.UserRepository.GetMembersAsync(userParams); Response.AddPaginationHeader(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages); return(Ok(users)); }
public async Task <ActionResult> UpdateUser(MemberUpdateDto memberUpdateDto) { //get username from the token (User claim principal is available in the parent class - ControllerBase) //get user entity from the DB var user = await _unitOfWork.UserRepository.GetUserByUserNameAsync(User.GetUserName()); //use mapper to update the user _mapper.Map(memberUpdateDto, user); //add tracking info to the db context - change status of the user object to EntityState.Modified _unitOfWork.UserRepository.Update(user); //save changes to the db if (await _unitOfWork.CompleteAsync()) { return(NoContent()); } return(BadRequest("Failed to update user")); }