Esempio n. 1
0
        public async Task <UserPreferenceOutput> Update([FromBody] UserPreferenceInput input)
        {
            var currentPreference = await GetEntity();

            if (currentPreference == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            currentPreference.AutoplayAudios      = input.AutoplayAudios;
            currentPreference.AutoplayVideos      = input.AutoplayVideos;
            currentPreference.NewsletterActivated = input.NewsletterActivated;

            currentPreference.InvisibleMode = input.InvisibleMode;
            if (currentPreference.InvisibleMode)
            {
                await SetAllDocumentsAsPrivate(currentPreference.UserId);
            }

            var result = Repository.Update(currentPreference);
            await Context.SaveChangesAsync();

            var output = Mapper.Map <UserPreferenceOutput>(result.Entity);

            return(output);
        }
Esempio n. 2
0
        public async Task <UserPreferenceOutput> Create([FromBody] UserPreferenceInput input)
        {
            var userId         = JwtReader.GetUserId();
            var userPreference = Mapper.Map <UserPreference>(input);

            userPreference.UserId = userId;

            if (userPreference.InvisibleMode)
            {
                await SetAllDocumentsAsPrivate(userId);
            }

            var result = await Repository.AddAsync(userPreference);

            await Context.SaveChangesAsync();

            var output = Mapper.Map <UserPreferenceOutput>(result.Entity);

            return(output);
        }