public IActionResult GetProblem(long id) { if (User.Identity.Name == null) { return(Ok()); } 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 = "Проблема не найдена" })); } return(Ok(new DataResponse <ProblemViewModel> { Data = new ProblemViewModel(problem) })); }
public IActionResult GetSession(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 = "Проблема не найдена" })); } if (problem.User != user) { return(BadRequest(new ResponseModel { Success = false, Message = "Доступ запрещен" })); } var session = SessionService.Get(sessionID); if (session == null) { return(NotFound(new ResponseModel { Success = false, Message = "Сессия не найдена" })); } if (session.Problem != problem) { return(BadRequest(new ResponseModel { Success = false, Message = "Доступ запрещен" })); } return(Ok(new DataResponse <SessionViewModel> { Data = GetFullSession(session) })); }
public IActionResult GetProblemAssets(long problemID) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } var problem = ProblemService.Get(problemID); if (problem == null) { return(NotFound(new ResponseModel { Success = false, Message = "Проблема не найдена" })); } if (problem.User != user) { return(BadRequest(new ResponseModel { Success = false, Message = "Доступ запрещен" })); } var images = ProblemImageService.GetProblemImages(problem) .Select(x => new ProblemImageViewModel(x)) .ToList(); var resources = ProblemResourceService.GetProblemResources(problem) .Select(x => GetFullProblemResource(x)) .ToList(); var sessions = SessionService.GetUserSessions(user) .Where(x => x.Problem == problem) .Select(x => GetFullSession(x)) .ToList(); return(Ok(new DataResponse <ClientProblemAssetsViewModel> { Data = new ClientProblemAssetsViewModel { Problem = new ProblemViewModel(problem), Images = images, Resources = resources, Sessions = sessions } })); }
public IActionResult ChangeSessionSpecialist([FromBody] CreateSessionRequest request, 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 specialist = SpecialistService.Get(request.SpecialistID); if (specialist == null) { return(NotFound(new ResponseModel { Success = false, Message = "Специалист не найден" })); } session.Specialist = specialist; session.Reward = specialist.Price; session.Status = SessionStatus.New; SessionService.Update(session); return(Ok(new ResponseModel())); }
public IActionResult CreateReview([FromBody] CreateReviewRequest request, 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 specialist = SpecialistService.Get(session.Specialist.ID); session.Specialist = specialist; SessionService.Update(session); var review = new Review { Session = session, Text = request.ReviewText, Score = request.Score }; ReviewService.Create(review); return(Ok(new ResponseModel())); }
public IActionResult CreateProblemSession([FromBody] CreateSessionRequest request, long id) { 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 specialist = SpecialistService.Get(request.SpecialistID); if (specialist == null) { return(NotFound(new ResponseModel { Success = false, Message = "Специалист не найден" })); } var session = new Session { Specialist = specialist, Problem = problem, Reward = specialist.Price, Status = SessionStatus.New, Date = DateTime.UtcNow }; SessionService.Create(session); return(Ok(new CreateSessionResponse { SessionID = session.ID })); }
public IActionResult GetProblemSessions(long id) { 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 = "Проблема не найдена" })); } if (problem.User != user) { return(BadRequest(new ResponseModel { Success = false, Message = "Доступ запрещен" })); } var sessions = SessionService.GetAll() .Where(x => x.Problem == problem) .OrderByDescending(x => x.Date) .Select(x => GetFullSession(x)) .ToList(); return(Ok(new DataResponse <List <SessionViewModel> > { Data = sessions })); }
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())); }
public IActionResult StartSession(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 = "Сессия не найдена" })); } if (session.Specialist == null) { return(Ok(new ResponseModel { Success = false, Message = "Не выбран специалист" })); } var wallet = UserWalletService.GetUserWallet(user); if (wallet == null) { return(NotFound(new ResponseModel { Success = false, Message = "Кошелек не найден" })); } var activeSessions = SessionService.GetActiveSessions(user); var lockedBalance = activeSessions.Sum(x => x.Reward); if ((wallet.Balance - lockedBalance) < session.Reward) { return(Ok(new ResponseModel { Success = false, Message = "Недостаточно средств" })); } session.Status = SessionStatus.Started; session.Date = DateTime.UtcNow; SessionService.Update(session); return(Ok(new ResponseModel())); }
public IActionResult ReloadClientProblemImage(long clientID, long problemID, long imageID) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } var specialist = SpecialistService.GetSpecialistFromUser(user); if (specialist == null) { return(NotFound(new ResponseModel { Success = false, Message = "Специалист не найден" })); } var client = UserService.Get(clientID); if (client == null) { return(NotFound(new ResponseModel { Success = false, Message = "Клиент не найден" })); } var problem = ProblemService.Get(problemID); if (problem == null) { return(NotFound(new ResponseModel { Success = false, Message = "Проблема не найдена" })); } if (problem.User != client) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } var image = ProblemImageService.Get(imageID); if (image == null) { return(NotFound(new ResponseModel { Success = false, Message = "Образ не найден" })); } var session = SessionService.GetCurrentSession(problem); if (session == null) { return(NotFound(new ResponseModel { Success = false, Message = "Активная сессия не найдена" })); } if (session.Problem != problem) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } image.IsHidden = false; ProblemImageService.Update(image); var problemImages = ProblemImageService.GetProblemImages(problem) .Select(x => new ProblemImageViewModel(x)) .ToList(); return(Ok(new DataResponse <List <ProblemImageViewModel> > { Data = problemImages })); }
public IActionResult EditClientProblemImage([FromBody] CreateUpdateProblemImageRequest request, long clientID, long problemID, long imageID) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } var specialist = SpecialistService.GetSpecialistFromUser(user); if (specialist == null) { return(NotFound(new ResponseModel { Success = false, Message = "Специалист не найден" })); } var client = UserService.Get(clientID); if (client == null) { return(NotFound(new ResponseModel { Success = false, Message = "Клиент не найден" })); } var problem = ProblemService.Get(problemID); if (problem == null) { return(NotFound(new ResponseModel { Success = false, Message = "Проблема не найдена" })); } if (problem.User != client) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } var session = SessionService.GetCurrentSession(problem); if (session == null) { return(NotFound(new ResponseModel { Success = false, Message = "Активная сессия не найдена" })); } if (session.Problem != problem) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } var problemImage = ProblemImageService.Get(imageID); if (problemImage == null) { return(NotFound(new ResponseModel { Success = false, Message = "Образ не найден" })); } if (request.Title != problemImage.Title) { problemImage.Title = request.Title; } if (request.Emotion != problemImage.Emotion) { problemImage.Emotion = request.Emotion; } if (request.Location != problemImage.Location) { problemImage.Location = request.Location; } if (request.Characteristic != problemImage.Characteristic) { problemImage.Characteristic = request.Characteristic; } if (request.IsMine != problemImage.IsMine) { problemImage.IsMine = request.IsMine; } if (request.IsIDo != problemImage.IsIDo) { problemImage.IsIDo = request.IsIDo; } if (request.IsForever != problemImage.IsForever) { problemImage.IsForever = request.IsForever; } if (request.LikeScore != problemImage.LikeScore) { problemImage.LikeScore = request.LikeScore; } long parentImageID = 0; if (problemImage.ParentImage != null) { parentImageID = problemImage.ParentImage.ID; } if (request.ParentImageID != 0 && request.ParentImageID != parentImageID) { var newParentImage = ProblemImageService.Get(request.ParentImageID); if (newParentImage == null) { return(NotFound(new ResponseModel { Success = false, Message = "Зависимость не найдена" })); } problemImage.ParentImage = newParentImage; } else if (request.ParentImageID == 0) { problemImage.ParentImage = null; } ProblemImageService.Update(problemImage); var problemImages = ProblemImageService.GetProblemImages(problem) .Select(x => new ProblemImageViewModel(x)) .ToList(); return(Ok(new DataResponse <List <ProblemImageViewModel> > { Data = problemImages })); }
public IActionResult GetClientAssets(long clientID, long problemID) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } var specialist = SpecialistService.GetSpecialistFromUser(user); if (specialist == null) { return(NotFound(new ResponseModel { Success = false, Message = "Специалист не найден" })); } var client = UserService.Get(clientID); if (client == null) { return(NotFound(new ResponseModel { Success = false, Message = "Клиент не найден" })); } var problem = ProblemService.Get(problemID); if (problem == null) { return(NotFound(new ResponseModel { Success = false, Message = "Проблема не найдена" })); } if (problem.User != client) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } return(Ok(new DataResponse <ProblemAssetsViewModel> { Data = new ProblemAssetsViewModel { Problem = new ProblemViewModel(problem), Images = ProblemImageService.GetProblemImages(problem).Select(x => new ProblemImageViewModel(x)).ToList(), Resources = ProblemResourceService.GetProblemResources(problem).Select(x => GetFullProblemResource(x)).ToList(), Sessions = SessionService.GetProblemSessions(problem).Select(x => GetSpecialistSession(x)).ToList() } })); }
public IActionResult CloseClientSession(long clientID, long problemID, long sessionID) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } var specialist = SpecialistService.GetSpecialistFromUser(user); if (specialist == null) { return(NotFound(new ResponseModel { Success = false, Message = "Специалист не найден" })); } var client = UserService.Get(clientID); if (client == null) { return(NotFound(new ResponseModel { Success = false, Message = "Клиент не найден" })); } var problem = ProblemService.Get(problemID); if (problem == null) { return(NotFound(new ResponseModel { Success = false, Message = "Проблема не найдена" })); } if (problem.User != client) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } var session = SessionService.Get(sessionID); if (session == null) { return(NotFound(new ResponseModel { Success = false, Message = "Сессия не найдена" })); } session.SpecialistCloseDate = DateTime.UtcNow; session.IsSpecialistClose = true; SessionService.Update(session); SessionsTimerService.AddSession(session); var sessions = SessionService.GetSpecialistSessions(specialist) .Where(x => x.Status == SessionStatus.Started && !x.IsSpecialistClose) .Select(x => GetSessionClientCard(x)) .ToList(); return(Ok(new DataResponse <List <SpecialistProfileActiveSessionViewModel> > { Data = sessions })); }
public IActionResult EditClientProblemResource([FromBody] CreateUpdateProblemResourceRequest request, long clientID, long problemID, long resourceID) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } var specialist = SpecialistService.GetSpecialistFromUser(user); if (specialist == null) { return(NotFound(new ResponseModel { Success = false, Message = "Специалист не найден" })); } var client = UserService.Get(clientID); if (client == null) { return(NotFound(new ResponseModel { Success = false, Message = "Клиент не найден" })); } var problem = ProblemService.Get(problemID); if (problem == null) { return(NotFound(new ResponseModel { Success = false, Message = "Проблема не найдена" })); } if (problem.User != client) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } var session = SessionService.GetCurrentSession(problem); if (session == null) { return(NotFound(new ResponseModel { Success = false, Message = "Активная сессия не найдена" })); } if (session.Problem != problem) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } var resource = ProblemResourceService.Get(resourceID); if (resource == null) { return(NotFound(new ResponseModel { Success = false, Message = "Ресурс не найден" })); } if (request.Title != resource.Title) { resource.Title = request.Title; } if (request.Emotion != resource.Emotion) { resource.Emotion = request.Emotion; } if (request.Location != resource.Location) { resource.Location = request.Location; } if (request.Characteristic != resource.Characteristic) { resource.Characteristic = request.Characteristic; } if (request.Influence != resource.Influence) { resource.Influence = request.Influence; } if (request.LikeScore != resource.LikeScore) { resource.LikeScore = request.LikeScore; } request.Tasks.ForEach(task => ProblemResourceTaskService.CreateUpdateTask(task, resource)); var resources = ProblemResourceService.GetProblemResources(problem) .Select(x => GetFullProblemResource(x)) .ToList(); return(Ok(new DataResponse <List <ProblemResourceViewModel> > { Data = resources })); }