Esempio n. 1
0
        public async Task <bool> SetRemoveBlocking(SetBlockingDTOIn blockData)
        {
            IDictionary <string, string> roleIds = uManager.Users.Where(x => x.UserName == blockData.DefendorUserName || x.UserName == blockData.IrritatorUserName).Select(x => new
            {
                Role = x.UserName == blockData.IrritatorUserName ? "Irritator" : "Defender",
                x.Id
            }).ToDictionary(x => x.Role, x => x.Id);

            var blocking = await blockingsRepository.All().FirstOrDefaultAsync(x => x.IrritatorId == roleIds["Irritator"] && x.DefenderId == roleIds["Defender"]);

            if (blocking is null)
            {
                await blockingsRepository.AddAssync(new UserBlocking
                {
                    DefenderId  = roleIds["Defender"],
                    IrritatorId = roleIds["Irritator"]
                });
            }
            else
            {
                blocking.DateOfCreation = DateTime.UtcNow;
                blocking.IsDeleted      = !blocking.IsDeleted;
            }
            await blockingsRepository.SaveChangesAsync();

            return(true);
        }
        public async Task <ActionResult <UserProfileData> > SetBlocking(SetBlockingDTOIn blockData)
        {
            await this.userDataService.SetRemoveBlocking(blockData);

            return(NoContent());
        }