public async Task SendNotification([FromBody] int userId)
        {
            var user         = _userService.GetById(userId);
            var notification = new Notification
            {
                Title              = "MGS зовёт!",
                Body               = "Нет времени объяснять, вот тебе картинка g****e из интернетов!",
                Dir                = "auto",
                Icon               = "https://memepedia.ru/wp-content/uploads/2018/10/g****e-donuts.png",
                Badge              = "https://panfilov.dev/assets/fox_transparent_background.png",
                Renotify           = true,
                Lang               = "en",
                RequireInteraction = false,
                Vibrate            = new[] { 200, 100, 200 }
            };

            _webPushService.SendNotification(user, notification); // TODO: add check whether notification was sent or not?
        }
Beispiel #2
0
        public async Task <User> Update(User user, int currentUserId)
        {
            var existingUser = await _databaseContext.Users.SingleOrDefaultAsync(u => u.Id == user.Id);

            if (existingUser == null)
            {
                throw new AppException("Not existing user");
            }

            var currentUser = await _databaseContext.Users.SingleOrDefaultAsync(u => u.Id == currentUserId);

            if (user.MainQuestStage != existingUser.MainQuestStage)
            {
                existingUser.BriefingPassed            = false;
                existingUser.NumberOfQuestInCurrentAct = 0;
                _webPushService.SendNotification(existingUser, GetNotification(user));
            }
            else
            {
                existingUser.NumberOfQuestInCurrentAct = user.NumberOfQuestInCurrentAct;
            }
            existingUser.DrebinPoints   = user.DrebinPoints;
            existingUser.MainQuestStage = user.MainQuestStage;
            existingUser.VkId           = user.VkId;

            if (currentUser.CanManagePermissions && existingUser.Id != currentUser.Id)
            {
                existingUser.CanManageUsers       = user.CanManageUsers;
                existingUser.CanManageOrders      = user.CanManageOrders;
                existingUser.CanManageProducts    = user.CanManageProducts;
                existingUser.CanManagePermissions = user.CanManagePermissions;
            }

            var updatedUser = _databaseContext.Users.Update(existingUser).Entity;

            _databaseContext.SaveChanges();

            return(updatedUser);
        }