public async Task <bool> UpdateProfile(CreateProfileDto profile)
        {
            Profile newProfile = new Profile
            {
                DisplayName = profile.DisplayName,
                Description = profile.Description,
                ProfileId   = profile.ProfileId,
            };

            _context.Entry(newProfile).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProfileExists(newProfile.ProfileId))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public IActionResult CreateProfile([FromBody] CreateProfileDto profile)
        {
            if (!_validateRepository.IsUserNameHandleUnique(profile.User.UserName, profile.Handle))
            {
                return(StatusCode(409, "User allready exists"));
            }

            var prof = AutoMapper.Mapper.Map <Profile>(profile);
            var salt = new byte[128 / 8];

            Random random = new Random();

            random.NextBytes(salt);

            prof.User.PasswordHash = _authorizationManager.GeneratePasswordHash(profile.User.Password, salt);
            prof.User.Salt         = salt;

            _profileRepository.CreateProfile(prof);

            if (!_profileRepository.Save())
            {
                return(StatusCode(500, "There was a problem while handling your request."));
            }

            return(StatusCode(200, "Profile created"));
        }
        [HttpPost] // Post means create
        public async Task <ActionResult <Profile> > CreateProfile(CreateProfileDto profile)
        {
            var profileDto = await profileRepository.CreateProfile(profile);


            return(CreatedAtAction("GetProfile", new { profileId = profileDto.Id }, profileDto));
        }
Ejemplo n.º 4
0
        private async Task RegisterNewUser()
        {
            try
            {
                IsBusy = true;

                CreateProfileDto newProfile = new CreateProfileDto
                {
                    IsPublic = IsPublic,
                    Handle   = UserName,
                    User     = new AccountDto
                    {
                        UserName = UserName,
                        Password = Password,
                        Email    = Email
                    }
                };

                await _profileService.CreateProfile(newProfile);

                await _navigationService.NavigateAsync <LoginViewModel>();
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> CreateProfile([FromBody] CreateProfileDto request)
        {
            var profile = new UserProfile(request.Username, request.FirstName, request.LastName);

            try
            {
                await profileStore.AddProfile(profile);

                logger.LogInformation(Events.ProfileCreated, "A Profile has been added for user {username}",
                                      request.Username);
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e, "Failed to create a profile for user {username}", request.Username);
                return(StatusCode(503, "Failed to reach storage"));
            }
            catch (DuplicateProfileException)
            {
                logger.LogInformation(Events.ProfileAlreadyExists,
                                      "The profile for user {username} cannot be created because it already exists",
                                      request.Username);
                return(StatusCode(409, "Profile already exists"));
            }
            catch (ArgumentException)
            {
                return(StatusCode(400, "Invalid or incomplete Request Body"));
            }
            catch (Exception e)
            {
                logger.LogError(Events.InternalError, e, "Failed to create a profile for user {username}", request.Username);
                return(StatusCode(500, "Failed to create profile"));
            }
            return(Created(request.Username, profile));
        }
Ejemplo n.º 6
0
        public async Task <bool> CreateProfile(CreateProfileDto profile)
        {
            UriBuilder builder = new UriBuilder(_runtimeContext.BaseEndpoint)
            {
                Path = "api/profiles"
            };

            var message = await _requestService.PostAsync <CreateProfileDto, string>(builder.Uri, profile);

            return(await Task.FromResult(true));
        }
        public void Initialize()
        {
            client = TestUtils.CreateTestServerAndClient();

            conversationDto1 = new AddConversationDto
            {
                Participants = new List <string> {
                    Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                }
            };
            conversationDto2 = new AddConversationDto
            {
                Participants = new List <string> {
                    conversationDto1.Participants[0], Guid.NewGuid().ToString()
                }
            };
            conversationDto3 = new AddConversationDto
            {
                Participants = new List <string> {
                    Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                }
            };
            conversationDto4 = new AddConversationDto
            {
                Participants = new List <string> {
                    conversationDto1.Participants[0], Guid.NewGuid().ToString()
                }
            };

            userProfile1 = new CreateProfileDto
            {
                Username  = conversationDto1.Participants[1],
                FirstName = Guid.NewGuid().ToString(),
                LastName  = Guid.NewGuid().ToString()
            };
            userProfile2 = new CreateProfileDto
            {
                Username  = conversationDto2.Participants[1],
                FirstName = Guid.NewGuid().ToString(),
                LastName  = Guid.NewGuid().ToString()
            };
            userProfile3 = new CreateProfileDto
            {
                Username  = conversationDto4.Participants[1],
                FirstName = Guid.NewGuid().ToString(),
                LastName  = Guid.NewGuid().ToString()
            };

            messageDto1 = new AddMessageDto("Hi!", conversationDto1.Participants[0]);
            messageDto2 = new AddMessageDto("Hello!", conversationDto1.Participants[1]);
            messageDto3 = new AddMessageDto("Hi!", "foo");
            messageDto4 = new AddMessageDto("Kifak!", conversationDto1.Participants[1]);
        }
        [HttpPut("{profileId}")] // Put Update
        public async Task <IActionResult> UpdateProfile(int profileId, CreateProfileDto profile)
        {
            if (profileId != profile.ProfileId)
            {
                return(BadRequest());
            }
            if (!await profileRepository.UpdateProfile(profile))
            {
                return(NotFound());
            }

            return(NoContent());
        }
        public async Task <IActionResult> CreateProfile([FromForm] CreateProfileDto createProfileDto, [FromQuery] bool edit)
        {
            Domain.Profile profile = null;

            if (edit)
            {
                profile = await _context.Profiles.Include(p => p.Skills).FirstOrDefaultAsync(p => p.UserId == UserId);

                if (profile.DisplayName != createProfileDto.DisplayName &&
                    _context.Profiles.Any(p => p.DisplayName == createProfileDto.DisplayName))
                {
                    return(BadRequest());
                }

                _context.Skills.RemoveRange(profile.Skills);

                _mapper.Map <CreateProfileDto, Domain.Profile>(createProfileDto, profile);

                if (createProfileDto.Avatar != null)
                {
                    var avatar = UploadImage(createProfileDto.Avatar);
                    profile.Avatar = avatar;
                }
            }
            else
            {
                if (createProfileDto.Avatar == null)
                {
                    return(BadRequest());
                }

                if (_context.Profiles.Any(p => p.DisplayName == createProfileDto.DisplayName))
                {
                    return(BadRequest());
                }

                profile        = _mapper.Map <Domain.Profile>(createProfileDto);
                profile.UserId = UserId;
                var avatar = UploadImage(createProfileDto.Avatar);
                profile.Avatar = avatar;

                _context.Profiles.Add(profile);
            }

            await _context.SaveChangesAsync();

            var profileDto = _mapper.Map <ProfileDto>(profile);

            return(Ok(profileDto));
        }
        public async Task CreateGetProfile()
        {
            var createProfileDto = new CreateProfileDto
            {
                Username  = Guid.NewGuid().ToString(),
                FirstName = "Nehme",
                LastName  = "Bilal"
            };

            await chatServiceClient.CreateProfile(createProfileDto);

            UserInfoDto userProfile = await chatServiceClient.GetProfile(createProfileDto.Username);

            Assert.AreEqual(createProfileDto.Username, userProfile.Username);
            Assert.AreEqual(createProfileDto.FirstName, userProfile.FirstName);
            Assert.AreEqual(createProfileDto.LastName, userProfile.LastName);
        }
        public async Task <ProfileDto> CreateProfile(CreateProfileDto profile, UserDto user)
        {
            Profile newProfile = new Profile
            {
                DisplayName = profile.DisplayName,
                Description = profile.Description
            };

            _context.Profiles.Add(newProfile);
            await _context.SaveChangesAsync();

            await CreateProfileMember(new CreateProfileMember
            {
                ProfileId = newProfile.ProfileId,
                UserId    = user.Id
            });

            return(await GetProfile(newProfile.ProfileId));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult <ProfileDto> > Register(RegisterData data)
        {
            var user = await userService.Register(data, this.ModelState);

            if (!ModelState.IsValid)
            {
                return(BadRequest(new ValidationProblemDetails(ModelState)));
            }

            CreateProfileDto profile = new CreateProfileDto {
                DisplayName = data.Username
            };

            var profileDto = await profileRepository.CreateProfile(profile, user);

            profileDto = await profileRepository.CreateProfileMember(new CreateProfileMember { ProfileId = profileDto.Id, UserId = user.Id });

            return(Ok(profileDto));
        }
        public async Task CreateProfile_InvalidDto(string username, string firstName, string lastName)
        {
            var createProfileDto = new CreateProfileDto
            {
                Username  = username,
                FirstName = firstName,
                LastName  = lastName
            };

            try
            {
                await chatServiceClient.CreateProfile(createProfileDto);

                Assert.Fail("A ChatServiceException was expected but was not thrown");
            }
            catch (ChatServiceException e)
            {
                Assert.AreEqual(HttpStatusCode.BadRequest, e.StatusCode);
            }
        }
        public async Task CreateDuplicateProfile()
        {
            var createProfileDto = new CreateProfileDto
            {
                Username  = Guid.NewGuid().ToString(),
                FirstName = "Nehme",
                LastName  = "Bilal"
            };

            await chatServiceClient.CreateProfile(createProfileDto);

            try
            {
                await chatServiceClient.CreateProfile(createProfileDto);

                Assert.Fail("A ChatServiceException was expected but was not thrown");
            }
            catch (ChatServiceException e)
            {
                Assert.AreEqual(HttpStatusCode.Conflict, e.StatusCode);
            }
        }
Ejemplo n.º 15
0
        public async Task CreateProfile(CreateProfileDto profileDto)
        {
            try
            {
                HttpResponseMessage response = await httpClient.PostAsync("api/profile",
                                                                          new StringContent(JsonConvert.SerializeObject(profileDto), Encoding.UTF8, "application/json"));

                if (!response.IsSuccessStatusCode)
                {
                    throw new ChatServiceException("Failed to create user profile", response.ReasonPhrase, response.StatusCode);
                }
            }
            catch (Exception e)
            {
                // make sure we don't catch our own exception we threw above
                if (e is ChatServiceException)
                {
                    throw;
                }

                throw new ChatServiceException("Failed to reach chat service", e, "Internal Server Error",
                                               HttpStatusCode.InternalServerError);
            }
        }
Ejemplo n.º 16
0
 public Task <bool> CreateProfile(CreateProfileDto profile)
 {
     throw new NotImplementedException();
 }