Exemplo n.º 1
0
        public async Task <Response <ProfileDto> > UpdateProfileAsync(string displayName, string email, string description, string googleId)
        {
            Response <ProfileDto> response = new();

            Profile profile = _context.Profiles.FirstOrDefault(x => x.GoogleId == googleId);

            if (profile == null)
            {
                return(response);
            }

            profile.DisplayName = displayName;
            profile.Email       = email;
            profile.Description = description;

            _context.Profiles.Update(profile);
            bool success = await _context.SaveChangesAsync() > 0;

            if (success)
            {
                response.Success = true;
                response.Data    = _mapper.Map <ProfileDto>(profile);
                UpdateProfileEvent(response.Data);
            }
            return(response);
        }
Exemplo n.º 2
0
        public async Task <bool> Consume(string message)
        {
            UserEvent userEvent = JsonConvert.DeserializeObject <UserEvent>(message);

            if (userEvent == null)
            {
                return(false);
            }

            Profile profile = new Profile
            {
                Id             = userEvent.Id,
                Avatar         = userEvent.Avatar,
                DisplayName    = userEvent.DisplayName,
                DateOfCreation = userEvent.DateOfCreation,
                Email          = userEvent.Email,
                GoogleId       = userEvent.GoogleId
            };

            await _context.Profiles.AddAsync(profile);

            bool success = await _context.SaveChangesAsync() > 0;

            if (!success)
            {
                return(false);
            }

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

            CreateProfileEvent(profileDto);

            return(true);
        }
Exemplo n.º 3
0
        public async Task FindNotExistingProfileById()
        {
            var entity = new Profile
            {
                Id          = new Guid("d1080a8c-a1b5-4b14-8d30-ee74dccc500d"),
                DisplayName = "John Doe",
                Avatar      = "picture.png",
                Description = "Test"
            };

            var result = await _profileService.GetProfileAsync(entity.Id);

            Assert.NotNull(result);
            Assert.False(result.Success);
            Assert.Null(result.Data);
        }
Exemplo n.º 4
0
        public async Task FindExistingProfileById()
        {
            var entity = new Profile
            {
                Id          = new Guid("d1080a8c-a1b5-4b14-8d30-ee74dccc500d"),
                DisplayName = "John Doe",
                Avatar      = "picture.png",
                Description = "Test"
            };

            Context.Profiles.Add(entity);
            await Context.SaveChangesAsync();

            var result = await _profileService.GetProfileAsync(entity.Id);

            Assert.NotNull(result);
            Assert.True(result.Success);
            Assert.AreEqual(entity.Id, result.Data.Id);
        }