Exemple #1
0
        public async Task <IActionResult> CreateFakeProfiles([FromBody] List <FakeProfileModel> users)
        {
            try
            {
                var cptrSucceed = 0;
                var cptrFailed  = 0;

                foreach (var user in users)
                {
                    var email = user.FirstName + "." + user.LastName + "@ululu.com";
                    var found = _profileRepository.GetProfileByUserName(email) != null;
                    if (found)
                    {
                        continue;
                    }

                    var avatarId = await _avatarRepository.CreateAvatarFromUrl(user.PhotoUrl);

                    var profile = new Profile
                    {
                        User = new CustomUser
                        {
                            FirstName = user.FirstName,
                            LastName  = user.LastName,
                            Email     = email,
                            AvatarId  = avatarId
                        }
                    };
                    var createdProfile = await _profileRepository.AddProfile(profile);

                    if (createdProfile != null)
                    {
                        cptrSucceed++;
                    }
                    else
                    {
                        cptrFailed++;
                    }
                }

                return(Ok(new CreateFakeProfilesResult {
                    CptrSucceed = cptrSucceed, CptrFailed = cptrFailed
                }));
            }
            catch
            {
                throw new ApplicationException();
            }
        }