Esempio n. 1
0
        public async Task <IActionResult> CreatePost(int profileId, PostForCreationDto PostForCreation)
        {
            if (profileId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            PostForCreation.ProfileId = profileId;

            var profile = await _repo.getProfile(profileId);

            if (profile == null)
            {
                return(BadRequest("Could Not Find Profile"));
            }

            var post = _mapper.Map <Posts>(PostForCreation);

            _repo.Add(post);

            if (await _repo.SaveAll())
            {
                var postToReturn = _mapper.Map <PostToReturnDto>(post);
                return(Ok(postToReturn));
            }

            return(BadRequest("Failed to upload Post"));
        }
Esempio n. 2
0
        public ProfileDescriptor CreateProfileDescriptor(ProfileModule module, string name)
        {
            ProfileEntity profileEntity = new ProfileEntity {
                Id = Guid.NewGuid(), Name = name, PluginGuid = module.PluginInfo.Guid
            };

            _profileRepository.Add(profileEntity);

            return(new ProfileDescriptor(module, profileEntity));
        }
Esempio n. 3
0
        public async Task <IActionResult> ProfileForm(ProfileViewModel ProfileVm)
        {
            User user = await userManager.FindByNameAsync(User.Identity.Name);

            await userManager.AddToRoleAsync(user, "TRAINER");

            Profile profile = new Models.Profile {
                City = ProfileVm.ProfileView.City, Descripiton = ProfileVm.ProfileView.Descripiton
            };
            var uploads = Path.Combine(_environment.WebRootPath);

            if (ProfileVm.File.Length > 0)
            {
                using (var fileStream = new FileStream(Path.Combine(uploads, ProfileVm.File.FileName), FileMode.Create))
                {
                    await ProfileVm.File.CopyToAsync(fileStream);
                }
            }
            // string name = HttpContext.User.Identity.Name;
            profile.ProfileUser = user;
            profile.imagePath   = $"\\{ProfileVm.File.FileName}";
            profileRepo.Add(profile);

            return(RedirectToAction("Index", "Profiles"));
        }
Esempio n. 4
0
        private void CreateProfileButton_Click(object sender, RoutedEventArgs e)
        {
            if (ProfileNameTextBox.Text.Length <= 3)
            {
                MessageBox.Show("Profile name is too short!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (PasswordBox.Password.Length <= 7)
            {
                MessageBox.Show("Password is too short!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var recoveryCode = RecoveryCodeGenerator.Instance.Generate();
            var profile      = new Profile(ProfileNameTextBox.Text, PasswordBox.Password, recoveryCode);

            var recoveryCodeWindow = new RecoveryCodeWindow(ProfileNameTextBox.Text, recoveryCode);

            recoveryCodeWindow.ShowDialog();

            profile = _profileRepository.Add(profile);

            MessageBox.Show($"Added profile named: {profile.Name} with id {profile.Id.ToString()}");

            RefreshProfiles();

            transitioner.SelectedIndex = 0;
        }
Esempio n. 5
0
        public override int Create(User entity)
        {
            var userId = _userRepository.Add(entity);

            if (userId != 0)
            {
                var contact =
                    new DomainModels.Contact
                {
                    EmailId     = entity.EmailId,
                    PhoneNumber = entity.PhoneNumber
                };

                var address = new Address
                {
                    AddressLine1 = ""
                };

                var profile = new DomainModels.Profile
                {
                    UserId   = userId,
                    FullName = entity.UserName,
                    Contact  = contact,
                    Address  = address,
                    DoB      = new DateTime()
                };

                _profileRepository.Add(profile);
            }

            return(userId);
        }
Esempio n. 6
0
        public void ShouldAddNewProfile()
        {
            var user = PerfilBuilder.New().WithId(id).Build();
            var ret  = profileRepository.Add(user);

            ret.Should().BeGreaterThan(0);
        }
Esempio n. 7
0
        public override Task <RegisterProfileUseCaseResponse> Handle(RegisterProfileUseCaseRequest request, CancellationToken cancellationToken = default)
        {
            IProfile profile = m_profileFactory.CreateProfile(request.Name, request.Email, request.Address);

            m_profileRepository.Add(profile);
            return(Task.FromResult(new RegisterProfileUseCaseResponse(profile.Id)));
        }
Esempio n. 8
0
 public bool Add(Profile item)
 {
     if (_profileRepository.GetSingleById(item.Id) == null)
     {
         _profileRepository.Add(item);
     }
     return(true);
 }
Esempio n. 9
0
        public async Task <bool> Handle(CreateProfileCommand request, CancellationToken cancellationToken)
        {
            // create a client for github
            var github = new GitHubClient(new ProductHeaderValue("MyAmazingApp"));
            var user   = await github.User.Get(request.GithubAccount);

            //if user not register in github we wont continue
            if (user == null)
            {
                return(false);
            }

            // check if user register before
            var existProfile = await _profileRepository.GetByEmail(request.Email);


            //if user register in our db before, we just updated the saved info and check if repos changed then update info in our db
            if (existProfile != null)
            {
                existProfile.Email         = request.Email;
                existProfile.Name          = request.Name;
                existProfile.Organization  = request.Organization;
                existProfile.GithubAccount = request.GithubAccount;
                existProfile.PhoneNumber   = request.PhoneNumber;
                _profileRepository.Update(existProfile);
                var updateResult = (await _profileRepository.UnitOfWork.SaveChangesAsync(cancellationToken)) > 0;
                await _mediator.Send(new CreateRepoCommand
                {
                    AccountName = request.GithubAccount,
                    ProfileId   = existProfile.Id
                }, cancellationToken);

                return(updateResult);
            }

            //if user not register in our db before , we submitted as new account and then get all the repos of user
            var createDto = new GithubProfile
            {
                Email         = request.Email,
                Name          = request.Name,
                Organization  = request.Organization,
                GithubAccount = request.GithubAccount,
                PhoneNumber   = request.PhoneNumber
            };

            _profileRepository.Add(createDto);
            var result = await _profileRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

            await _mediator.Send(new CreateRepoCommand
            {
                AccountName = request.GithubAccount,
                ProfileId   = createDto.Id
            }, cancellationToken);

            return(result);
        }
Esempio n. 10
0
 private Profile CreateProfileSlim(Profile profile)
 {
     ValidatePassword(profile.Password);
     profile.Password  = profile.Password.HashPassword();
     profile.ProfileId = idMapBSO.GetNextID(EntityConstants.IDMAP_PROFILEID);
     profile.Status    = EntityConstants.PROFILE_STATUS_ACTIVE;
     profile           = profileRepo.Add(profile);
     logger.LogInformation("PartyBSO: profile created.\n" + ObjectDumper.Dump(profile));
     return(profile);
 }
        public async Task <IActionResult> Post([FromBody] Profile profile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // _logger.LogInformation($"New profile added - {profile.FullName}");

            return(Ok(_profileRepo.Add(profile)));
        }
Esempio n. 12
0
        public Profile CreateProfile(ProfileModule module, string name)
        {
            var profile = new Profile(module.PluginInfo, name);

            _profileRepository.Add(profile.ProfileEntity);

            if (_surfaceService.ActiveSurface != null)
            {
                profile.PopulateLeds(_surfaceService.ActiveSurface);
            }

            return(profile);
        }
Esempio n. 13
0
        public async Task <bool> Execute(ProfileAggregate profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException(nameof(profile));
            }

            var pr = await _profileRepository.Get(profile.Subject);

            if (pr == null)
            {
                return(await _profileRepository.Add(new[] { profile }));
            }

            return(await _profileRepository.Update(new[] { profile }));
        }
Esempio n. 14
0
        public IActionResult Create([FromBody] Profile item)
        {
            try
            {
                if (item == null || !ModelState.IsValid)
                {
                    return(BadRequest("Invalid State"));
                }

                ProfileRepository.Add(item);
            }
            catch (Exception)
            {
                return(BadRequest("Error while creating"));
            }
            return(Ok(item));
        }
Esempio n. 15
0
        public void Save(IProfile profile, out bool success)
        {
            Checks.Argument.IsNotNull(profile, "profile");

            success = false;

            if (null == _repo.FindByProfileId(profile.ProfileId))
            {
                try
                {
                    _repo.Add(profile);
                    success = true;
                }
                catch (Exception ex)
                {
                    success = false;
                }
            }
        }
Esempio n. 16
0
 public int Add(ProfileDTO item)
 {
     return(repo.Add(mapper.Map <data.Profile>(item)));
 }
Esempio n. 17
0
 public void CreateProfile(Profile profile)
 {
     _iProfileRepository.Add(profile);
     Save();
 }
 public async Task AddAndSafe(Profile Profile)
 {
     _ProfileRepository.Add(Profile);
     await _ProfileRepository.Save();
 }
Esempio n. 19
0
 public void CreateProfile(Profiles Profile)
 {
     ProfileRepository.Add(Profile);
 }
Esempio n. 20
0
        public int Add(ProfileDTO item)
        {
            var dto = mapper.Map <Profile>(item);

            return(repo.Add(dto));
        }
Esempio n. 21
0
 public void Add(Profile profile)
 {
     _profileRepository.Add(profile);
 }
Esempio n. 22
0
 Profile IProfileService.Add(Profile newProfile)
 {
     return(_profileRepository.Add(newProfile));
 }
Esempio n. 23
0
 public Profile Add(Profile newProfile)
 {
     return(_profileRepository.Add(newProfile));
 }
        public async Task <bool> Execute(string localSubject, string externalSubject, string issuer, bool force = false)
        {
            if (string.IsNullOrWhiteSpace(localSubject))
            {
                throw new ArgumentNullException(nameof(localSubject));
            }

            if (string.IsNullOrWhiteSpace(externalSubject))
            {
                throw new ArgumentNullException(nameof(externalSubject));
            }

            if (string.IsNullOrWhiteSpace(issuer))
            {
                throw new ArgumentNullException(nameof(issuer));
            }

            var resourceOwner = await _resourceOwnerRepository.GetAsync(localSubject);

            if (resourceOwner == null)
            {
                throw new IdentityServerException(Errors.ErrorCodes.InternalError, Errors.ErrorDescriptions.TheResourceOwnerDoesntExist);
            }

            var profile = await _profileRepository.Get(externalSubject);

            if (profile != null && profile.ResourceOwnerId != localSubject)
            {
                if (!force)
                {
                    throw new ProfileAssignedAnotherAccountException();
                }
                else
                {
                    await _profileRepository.Remove(new[] { externalSubject });

                    if (profile.ResourceOwnerId == profile.Subject)
                    {
                        await _resourceOwnerRepository.DeleteAsync(profile.ResourceOwnerId);
                    }

                    profile = null;
                }
            }

            if (profile != null)
            {
                throw new IdentityServerException(Errors.ErrorCodes.InternalError, Errors.ErrorDescriptions.TheProfileAlreadyLinked);
            }

            return(await _profileRepository.Add(new[]
            {
                new ResourceOwnerProfile
                {
                    ResourceOwnerId = localSubject,
                    Subject = externalSubject,
                    Issuer = issuer,
                    CreateDateTime = DateTime.UtcNow,
                    UpdateTime = DateTime.UtcNow
                }
            }));
        }