public ServiceDetail Save(ServiceDetail serviceDetail)
 {
     return(_serviceDetailDao.InsertOrUpdate(serviceDetail));
 }
Esempio n. 2
0
        public void DuplicateSection(ServiceRegisterViewModel model, Guid idAccount)
        {
            var service = ConvertService.FromServiceRegisterViewModel(model);

            var section = GetCurrentSection(service, Guid.Parse(model.CurrentSection));

            if (section.IdSection == Guid.Empty || section.IdSection == null)
            {
                var beforeSections = service.ServiceDetails.Where(s => s.Order <= section.Order).OrderBy(s => s.Order).ToList();
                var afterSections  = service.ServiceDetails.Where(s => s.Order > section.Order).OrderBy(s => s.Order).ToList();

                service.ServiceDetails.Clear();

                service.ServiceDetails.AddRange(beforeSections);

                section.Id = Guid.Empty;
                section.Questions.ForEach(q => q.Id = Guid.Empty);
                section.Questions.ForEach(q => q.QuestionDetails.ForEach(d => d.Id = Guid.Empty));

                section.Sections.ForEach(a => a.Id = Guid.Empty);
                section.Sections.ForEach(a => a.Questions.ForEach(q => q.Id = Guid.Empty));
                section.Sections.ForEach(a => a.Questions.ForEach(q => q.QuestionDetails.ForEach(d => d.Id = Guid.Empty)));

                service.ServiceDetails.Add(section);
                service.ServiceDetails.AddRange(afterSections);
            }
            else
            {
                var serviceDetail  = service.ServiceDetails.FirstOrDefault(s => s.Id == section.IdSection);
                var beforeSections = serviceDetail.Sections.Where(s => s.Order <= section.Order).OrderBy(s => s.Order).ToList();
                var afterSections  = serviceDetail.Sections.Where(s => s.Order > section.Order).OrderBy(s => s.Order).ToList();

                serviceDetail.Sections.Clear();
                serviceDetail.Sections.AddRange(beforeSections);

                section.Id = Guid.Empty;
                section.Questions.ForEach(q =>
                {
                    q.Id = Guid.Empty;
                    q.IdServiceDetail = Guid.Empty;
                });
                section.Questions.ForEach(q => q.QuestionDetails.ForEach(d =>
                {
                    d.Id         = Guid.Empty;
                    d.IdQuestion = Guid.Empty;
                }));

                section = _serviceDetailDao.InsertOrUpdate(section);

                var newSection = _serviceDetailDao.GetNotTracked(section.Id, idAccount);

                if (newSection == null)
                {
                }

                newSection.Questions.ForEach(q =>
                {
                    q.ServiceDetail = null;
                    q.QuestionDetails.ForEach(d =>
                    {
                        d.Question = null;
                    });
                });

                serviceDetail.Sections.Add(newSection);
                serviceDetail.Sections.AddRange(afterSections);

                var beforeDetails =
                    service.ServiceDetails.Where(s => s.Order < serviceDetail.Order).OrderBy(s => s.Order).ToList();
                var afterDetails =
                    service.ServiceDetails.Where(s => s.Order > serviceDetail.Order).OrderBy(s => s.Order).ToList();

                service.ServiceDetails.Clear();
                service.ServiceDetails.AddRange(beforeDetails);
                service.ServiceDetails.Add(serviceDetail);
                service.ServiceDetails.AddRange(afterDetails);
            }

            //UpdateEntireService(service, idAccount);
        }