Beispiel #1
0
        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
                }
            }));
        }
Beispiel #2
0
 private SpecialistProfileActiveSessionViewModel GetSessionClientCard(Session session)
 {
     return(new SpecialistProfileActiveSessionViewModel
     {
         Session = new SessionViewModel(session),
         Client = GetClientCard(session.Problem.User, session.Specialist),
         ImagesCount = ProblemImageService.GetProblemImages(session.Problem).Count,
         ResourcesCount = ProblemResourceService.GetProblemResources(session.Problem).Count
     });
 }
Beispiel #3
0
        private SpecialistSessionViewModel GetSpecialistSession(Session session)
        {
            var images    = ProblemImageService.GetProblemImages(session.Problem);
            var resources = ProblemResourceService.GetProblemResources(session.Problem);

            var result = new SpecialistSessionViewModel
            {
                SessionID             = session.ID,
                SessionDate           = session.Date,
                SessionStatus         = session.Status,
                Client                = new UserViewModel(session.Problem.User),
                Problem               = new ProblemViewModel(session.Problem),
                ProblemText           = session.Problem.ProblemText,
                Reward                = session.Reward,
                Specialist            = GetFullSpecialist(session.Specialist),
                IsSpecialistClose     = session.IsSpecialistClose,
                IsClientClose         = session.IsClientClose,
                SpecialistCloseDate   = session.SpecialistCloseDate,
                ClientCloseDate       = session.ClientCloseDate,
                SessionImagesCount    = images.Where(x => x.Session == session).Count(),
                TotalImagesCount      = images.Count,
                SessionResourcesCount = resources.Where(x => x.Session == session).Count(),
                TotalResourcesCount   = resources.Count
            };

            var review = ReviewService.GetSessionReview(session);

            if (review != null)
            {
                result.Review      = new ReviewViewModel(review);
                result.ReviewScore = review.Score;
            }

            images.ForEach(image =>
            {
                if (image.Session.Specialist != session.Specialist)
                {
                    result.IsAllImagesFromOneSpecialist = false;
                }
            });

            resources.ForEach(resource =>
            {
                if (resource.Session.Specialist != session.Specialist)
                {
                    result.IsAllResourcesFromOneSpecialist = false;
                }
            });

            return(result);
        }
Beispiel #4
0
        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()
                }
            }));
        }
Beispiel #5
0
        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
            }));
        }