private void CloseSession(Session session)
        {
            var renewSession = SessionService.Get(session.ID);

            if (renewSession.IsClientClose)
            {
                SessionsQuenue.Remove(session);
                return;
            }

            var clientWallet     = UserWalletService.GetUserWallet(session.Problem.User);
            var specialistWallet = UserWalletService.GetUserWallet(session.Specialist.User);

            clientWallet.Balance     -= session.Reward;
            specialistWallet.Balance += session.Reward;

            session.IsClientClose   = true;
            session.Status          = SessionStatus.Success;
            session.ClientCloseDate = DateTime.UtcNow;

            SessionService.Update(session);
            UserWalletService.Update(clientWallet);
            UserWalletService.Update(specialistWallet);

            SessionsQuenue.Remove(session);
        }
Example #2
0
        public IActionResult SuccessPayment([FromQuery] RegisterDOWebhook data)
        {
            var payment = PaymentService.GetPaymentByOrderID(data.OrderId);

            if (payment == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Платеж не найден"
                }));
            }

            payment.Status = PaymentStatus.Completed;
            PaymentService.Update(payment);

            payment.Wallet.Balance += payment.Amount;
            UserWalletService.Update(payment.Wallet);

            if (data.SessionId != 0)
            {
                var session = SessionService.Get(data.SessionId);
                if (session == null)
                {
                    return(NotFound(new ResponseModel
                    {
                        Success = false,
                        Message = "Платеж выполнен, но указанная сессия не найдена"
                    }));
                }

                session.Date   = DateTime.UtcNow;
                session.Status = SessionStatus.Started;

                SessionService.Update(session);
            }

            return(RedirectResult("profile?deposit=success"));
        }
Example #3
0
        public IActionResult CloseSession(long id, long sessionID)
        {
            var user = UserService.Get(long.Parse(User.Identity.Name));

            if (user == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Пользователь не найден"
                }));
            }

            var problem = ProblemService.Get(id);

            if (problem == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Проблема не найдена"
                }));
            }

            var session = SessionService.Get(sessionID);

            if (session == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Сессия не найдена"
                }));
            }

            var wallet = UserWalletService.GetUserWallet(user);

            if (wallet == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Кошелек не найден"
                }));
            }

            var specialistWallet = UserWalletService.GetUserWallet(session.Specialist.User);

            if (specialistWallet == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Кошелек не найден"
                }));
            }

            if (!session.IsSpecialistClose)
            {
                return(BadRequest(new ResponseModel
                {
                    Success = false,
                    Message = "Сессию не завершил специалист"
                }));
            }

            wallet.Balance -= session.Reward;
            UserWalletService.Update(wallet);

            specialistWallet.Balance += session.Reward;
            UserWalletService.Update(specialistWallet);

            session.IsClientClose   = true;
            session.ClientCloseDate = DateTime.UtcNow;
            session.Status          = SessionStatus.Success;
            SessionService.Update(session);

            var clientActiveSessions = SessionService.GetActiveSessions(session.Problem.User);

            NotificationsService.SendUpdateToUser(
                session.Problem.User.ID,
                SocketMessageType.BalanceUpdate,
                new UserWalletViewModel(wallet, clientActiveSessions.Sum(x => x.Reward)));

            NotificationsService.SendUpdateToUser(
                session.Specialist.ID,
                SocketMessageType.BalanceUpdate,
                new UserWalletViewModel(specialistWallet, 0));

            return(Ok(new ResponseModel()));
        }