Exemplo n.º 1
0
        public SurveysResultWithConclusionContent GetSurveysResults(long personId, long surveysResultId)
        {
            using (var surveysResultRepository = new BaseRepository<SurveysResult>())
            {
                if (!surveysResultRepository.Context.Persons.Any(x => x.Id == personId))
                {
                    throw new PersonDoesNotExistException();
                }

                SurveysResult surveysResult =
                    surveysResultRepository.Context.SurveysResults.Include("Conclusions").Include("Person").
                        FirstOrDefault(x => x.Id == surveysResultId);
                if (surveysResult == null)
                {
                    return null;
                }

                //if (surveysResult.Person.Id != personId)
                //{
                //    if (surveysResult.Parent != null)
                //    {
                //        if (surveysResult.Parent.Person.Id != personId)
                //        {
                //            throw new UserRightsException();
                //        }
                //    }
                //    else
                //    {
                //        if (!surveysResult.SurveysPersonsGroups.Any(x => x.Person.Id == personId))
                //        {
                //            throw new UnauthorizedException();
                //        }
                //    }
                //}

                //if (surveysResult.Person.Id != personId && surveysResult.Parent.Person.Id != personId
                //    && !surveysResult.SurveysPersonsGroups.Any(x => x.Person.Id == personId))
                //{
                //    throw new UserRightsException();
                //}

                Test test = surveysResultRepository.Context.Tests.FirstOrDefault(x => x.Id == surveysResult.MethodsId);

                // Form SurveysWithConclusion conctent
                SurveysResultWithConclusionContent content = new SurveysResultWithConclusionContent();
                content.Id = surveysResult.Id;
                content.PersonId = surveysResult.Person.Id;
                content.MethodsType = surveysResult.MethodsType;
                content.MethodsId = surveysResult.MethodsId;
                content.Date = surveysResult.Date;
                content.Name = surveysResult.Name;
                content.IsCompleted = surveysResult.IsCompleted;
                if(surveysResult.Parent != null)
                {
                    content.ParentId = surveysResult.Parent.Id;
                }
                content.Conclusions = new List<SurveysConclusionItem>();

                foreach (var conclusion in surveysResult.Conclusions)
                {
                    Object data = null;
                    if (test != null && !String.IsNullOrWhiteSpace(conclusion.Data))
                    {
                        data = ResultConverter.GenerateDataObject(test.CodeName, conclusion.Data);
                    }
                    if (data == null)
                    {
                        data = String.Empty;
                    }

                    SurveysConclusionItem conclusionItem = new SurveysConclusionItem()
                                                               {
                                                                   Id = conclusion.Id,
                                                                   SurveysResultId = conclusion.SurveysResult.Id,
                                                                   ServiceId = conclusion.Service.Id,
                                                                   Data = data,
                                                                   Ordered = conclusion.Ordered,
                                                                   Paid = conclusion.Paid,
                                                                   Processed = conclusion.Processed
                                                               };
                    content.Conclusions.Add(conclusionItem);
                }

                List<SurveysResult> childSurveysResults =
                    surveysResultRepository.GetAllItems.Where(x => x.Parent.Id == surveysResult.Id).ToList();
                if (childSurveysResults != null)
                {
                    content.SurveysResults = new List<SurveysResultWithConclusionContent>();
                    foreach (var childSurveysResult in childSurveysResults)
                    {
                        content.SurveysResults.Add(new SurveysResultWithConclusionContent()
                                                       {
                                                           Id = childSurveysResult.Id,
                                                           Date = childSurveysResult.Date,
                                                           MethodsId = childSurveysResult.MethodsId,
                                                           MethodsType = childSurveysResult.MethodsType,
                                                           Name = childSurveysResult.Name,
                                                           PersonId = childSurveysResult.Person.Id,
                                                           IsCompleted = childSurveysResult.IsCompleted,
                                                           ParentId = childSurveysResult.Parent.Id
                                                       });
                    }
                }

                return content;

            }
        }
Exemplo n.º 2
0
        public SurveysConclusionItem GetConclusion(long conclusionId)
        {
            using (var conclusionRepository = new BaseRepository<Conclusion>())
            {
                Conclusion conclusion =
                    conclusionRepository.Context.Conclusions.Include("Service").Include("SurveysResult").FirstOrDefault(
                        x => x.Id == conclusionId);
                if (conclusion == null)
                {
                    return null;
                }
                Test test = conclusionRepository.Context.Tests.FirstOrDefault(x => x.Id == conclusion.SurveysResult.MethodsId);

                SurveysConclusionItem item = new SurveysConclusionItem();
                Object data = null;
                if (test != null && !String.IsNullOrWhiteSpace(conclusion.Data))
                {
                    data = ResultConverter.GenerateDataObject(test.CodeName, conclusion.Data);
                }
                if (data == null)
                {
                    data = String.Empty;
                }

                SurveysConclusionItem conclusionItem = new SurveysConclusionItem()
                {
                    Id = conclusion.Id,
                    SurveysResultId = conclusion.SurveysResult.Id,
                    ServiceId = conclusion.Service.Id,
                    Data = data,
                    Ordered = conclusion.Ordered,
                    Paid = conclusion.Paid,
                    Processed = conclusion.Processed
                };
                return conclusionItem;
            }
        }
Exemplo n.º 3
0
        public CuratorSurveysWithChildContent GetCuratorSurveysResultsByPerson(long curatorId, long surveysResultId, long personId)
        {
            using (var surveysRepository = new BaseRepository<SurveysResult>())
            {
                Client curator = surveysRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
                if (curator == null)
                {
                    throw new UserDoesNotExistException();
                }

                SurveysResult surveysResult =
                   surveysRepository.GetAllItems.FirstOrDefault(x => x.Id == surveysResultId && String.Equals(x.MethodsType, Constraints.KMethodsTypeCuratorGroup));
                if (surveysResult == null)
                {
                    throw new SurveysResultDoesNotExistException();
                }

                Person person = surveysRepository.Context.Persons.FirstOrDefault(x => x.Id == personId && x.Curator.Id == curator.Id);
                if(person == null)
                {
                    throw new PersonDoesNotExistException();
                }

                if (surveysResult.Person.Id != curator.PersonId)
                {
                    throw new SurveysResultDoesNotExistException();
                }

                ICollection<SurveysResult> childSurveysResults =
                    surveysRepository.GetAllItems.Where(x => x.Parent.Id == surveysResult.Id && x.Person.Id == person.Id).ToList();
                // Fill CuratorSurveysWithChildContent content
                CuratorSurveysWithChildContent content = new CuratorSurveysWithChildContent();
                content.Id = surveysResult.Id;
                content.PersonId = surveysResult.Person.Id;
                content.MethodsType = surveysResult.MethodsType;
                content.MethodsId = surveysResult.MethodsId;
                content.Date = surveysResult.Date;
                content.SurveysResults = new List<SurveysResultWithConclusionContent>();
                foreach (var childSurveysResult in childSurveysResults)
                {
                    SurveysResultWithConclusionContent webSurveysResult = new SurveysResultWithConclusionContent()
                    {
                        Id = childSurveysResult.Id,
                        PersonId = childSurveysResult.Person.Id,
                        MethodsId = childSurveysResult.MethodsId,
                        MethodsType = childSurveysResult.MethodsType,
                        Name = childSurveysResult.Name,
                        IsCompleted = childSurveysResult.IsCompleted,
                        ParentId = childSurveysResult.Parent.Id,
                        Date = childSurveysResult.Date
                    };
                    List<Conclusion> conclusions =
                        surveysRepository.Context.Conclusions.Where(x => x.SurveysResult.Id == childSurveysResult.Id).
                            ToList();
                    webSurveysResult.Conclusions = new List<SurveysConclusionItem>();
                    foreach(var conclusion in conclusions)
                    {
                        SurveysConclusionItem item = new SurveysConclusionItem()
                                                         {
                                                             Id = conclusion.Id,
                                                             Data = conclusion.Data,
                                                             ServiceId = conclusion.Service.Id,
                                                             SurveysResultId = conclusion.SurveysResult.Id,
                                                             Ordered = conclusion.Ordered,
                                                             Paid = conclusion.Paid,
                                                             Processed = conclusion.Processed
                                                         };
                        webSurveysResult.Conclusions.Add(item);
                    }
                    content.SurveysResults.Add(webSurveysResult);
                }
                return content;
            }
        }