public async Task <Unit> Handle(SaveProfileCommand request, CancellationToken cancellationToken)
            {
                var profiles = await _profilesRepository.GetProfiles();

                var profile = profiles.FirstOrDefault(p => p.Id == request.Profile.Id);

                if (profile == null)
                {
                    profile    = request.Profile;
                    profile.Id = Guid.NewGuid();

                    profiles.Add(profile);
                }
                else
                {
                    Console.WriteLine("Mapping");
                    profile.Map(request.Profile);
                }

                profiles.UpdateIsSelected(profile);

                Console.WriteLine("Save profiles");
                await _profilesRepository.SaveProfiles(profiles);

                return(Unit.Value);
            }
Ejemplo n.º 2
0
 public IActionResult GetProfiles()
 {
     try
     {
         return(Ok(_profileRepository.GetProfiles()));
     }
     catch
     {
         return(NotFound());
     }
 }
Ejemplo n.º 3
0
        public async Task <PagingModel <ProfileDto> > GetAll(int page, int pageSize, string filter = null)
        {
            try
            {
                ProfileFilter profileFilter = null;

                if (filter != null)
                {
                    profileFilter = JsonSerializer.Deserialize <ProfileFilter>(filter);
                }

                return(await profilesRepository.GetProfiles(profileFilter, page, pageSize));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
            public async Task <Unit> Handle(SelectProfileCommand request, CancellationToken cancellationToken)
            {
                var profiles = await _profilesRepository.GetProfiles();

                var profile = profiles.FirstOrDefault(p => p.Id == request.ProfileId);

                if (profile == null)
                {
                    return(Unit.Value);
                }

                profile.IsSelected = true;
                profiles.UpdateIsSelected(profile);

                await _profilesRepository.SaveProfiles(profiles);

                return(Unit.Value);
            }
Ejemplo n.º 5
0
            public async Task <Unit> Handle(DeleteProfileCommand request, CancellationToken cancellationToken)
            {
                var profiles = await _profilesRepository.GetProfiles();

                if (request.ProfileId == Guid.Empty)
                {
                    // Not supported.
                    return(Unit.Value);
                }

                var profile = profiles.FirstOrDefault(p => p.Id == request.ProfileId);

                if (profile == null)
                {
                    return(Unit.Value);
                }

                profiles.Remove(profile);
                profiles.UpdateIsSelected();

                await _profilesRepository.SaveProfiles(profiles);

                return(Unit.Value);
            }
            public async Task <Profile?> Handle(GetCurrentProfileQuery request, CancellationToken cancellationToken)
            {
                var profiles = await _profilesRepository.GetProfiles();

                return(profiles.FirstOrDefault(p => p.IsSelected));
            }
 public Task <List <Profile> > Handle(GetAllProfilesQuery request, CancellationToken cancellationToken)
 {
     return(_profilesRepository.GetProfiles());
 }