public bool UpdateUser(PublicUserDTO userDto) { //var user = userDto.ToPublicUser(); var oldUser = _dBContext.PublicUsers.FirstOrDefault(u => u.UserId == userDto.Id); if (oldUser == null) { oldUser = _dBContext.PublicUsers.FirstOrDefault(u => u.Username == userDto.Username); if (oldUser == null) { return(false); } } oldUser.Birthdate = userDto.Birthdate; oldUser.FullName = userDto.FullName; oldUser.IdentityNumber = userDto.IdentityNumber; oldUser.ImageURL = userDto.ImageUrl; oldUser.IsActive = userDto.IsActive; oldUser.Mail = userDto.Mail; oldUser.NationalityId = userDto.NationalityId; oldUser.Phone = userDto.Phone; oldUser.NotificationToken = userDto.NotificationToken; //_dBContext.PublicUsers.Attach(user); _dBContext.Entry(oldUser).State = EntityState.Modified; return(_dBContext.SaveChanges() > 0); }
public static PublicUser ToPublicUser(this PublicUserDTO input) { if (input == null) { return(null); } return(new PublicUser() { Mail = input.Mail, UserId = input.Id, FullName = input.FullName, Username = input.Username, Password = input.EncPassword, IsActive = input.IsActive, Phone = input.Phone, Salt = input.Salt, Birthdate = input.Birthdate, IdentityNumber = input.IdentityNumber, ImageURL = input.ImageUrl, IssueDate = input.Issuedate, NationalityId = input.NationalityId, NotificationToken = input.NotificationToken }); }
public bool AddNewUser(string password, PublicUserDTO userDto) { try { var userentity = userDto.ToPublicUser();// userDto.ToUser(); var salt = new Byte[32]; using (var provider = new System.Security.Cryptography.RNGCryptoServiceProvider()) { provider.GetBytes(salt); // Generated salt } var pbkdf2 = new System.Security.Cryptography.Rfc2898DeriveBytes(password, salt); pbkdf2.IterationCount = 1000; byte[] hash = pbkdf2.GetBytes(32); // Hashed and salted password userentity.Salt = salt; userentity.Password = hash; userentity.IssueDate = DateTime.Now; _dBContext.PublicUsers.Add(userentity); return(_dBContext.SaveChanges() > 0); } catch (Exception ex) { return(false); } }
public List <VideoDTO> getFavouriteVideos(PublicUserDTO user) { // If the userId is nul the user does not exist int?userId = _mapper.getUserId(user.username); if (userId == null) { throw new InvalidParametersException("User cannot be found"); } // Do a Datalayer Call return(_mapper.getFavouriteVideos((int)userId)); }
// [Route("api/users/admin")] public IEnumerable <PublicUserDTO> GetAllAdmin() { return(GetDummyDB().Select(user => { //user.AccessType = EAccessType.Admin; //user.Address.Access = EAccessType.Admin; PublicUserDTO userDTO = new PublicUserDTO(); userDTO.Id = user.Id; userDTO.Name = user.Name; return userDTO; })); }
// [Route("api/users/public")] public IEnumerable <PublicUserDTO> GetAllPublic() { return(GetDummyDB().Select(user => { //user.AccessType = EAccessType.Public; //user.Address.Access = EAccessType.Public; PublicUserDTO userDTO = new PublicUserDTO() { Id = user.Id, Name = user.Name }; return userDTO; })); }
public IActionResult getProfile(PublicUserDTO user) { // Basic API -> Service Cals // Receive Object Through Post/Get Request // Pass Object Too Service Layer // Catch Defined Errors Else Return 2xx Message try { return(Ok(_userService.getProfile(user))); } catch (InvalidParametersException e) { return(BadRequest(e.Message)); } catch (DuplicateException e) { return(new BadRequestObjectResult(e.Message)); } }
public PublicUserDTO PublicUserById(int id) { PublicUserDTO response = null; using (var entities = new UCAInvestDBEntities()) { var dbResponse = entities.users.SingleOrDefault(t => t.user_id == id); if (dbResponse != null) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <User, PublicUserDTO>(); }); IMapper iMapper = config.CreateMapper(); response = iMapper.Map <User, PublicUserDTO>(dbResponse); } } return(response); }
public ProfileDTO getProfile(PublicUserDTO user) { // If the userId is nul the user does not exist int?userId = _mapper.getUserId(user.username); if (userId == null) { throw new InvalidParametersException("User cannot be found"); } User userInfo = _mapper.getUserInfo(user.username); ProfileDTO profile = new ProfileDTO { username = user.username, email = userInfo.email, friends = getFriends(user), favourites = getFavouriteVideos(user) }; return(profile); }