public bool Save(ReviewModel model)
        {
            var reviewManager = new ReviewManager();

            var review = new Review();
            review.Restaurant = new RestaurantManager().Get(model.RestaurantId);
            review.ReviewTime = DateTime.Now;
            review.Comment = model.Comment;
            review.Author = GetUserInfo();
            review.Food = model.Food;
            review.Ambience = model.Ambience;
            review.Service = model.Service;

            reviewManager.Add(review);

            return true;
        }
Example #2
0
        public int ImportCategory(XmlNodeList nodes)
        {
            ReviewManager reviewManager = new ReviewManager();

            int count = 0;

            foreach (XmlNode x in nodes)
            {
                ReviewModel newItem = new ReviewModel();
                try
                {
                    XmlNodeList temp;
                    if (x["id"] != null)
                    {
                        newItem.CommonSenseMediaID = x["id"].InnerText;
                    }
                    if (x["link"] != null)
                    {
                        newItem.ExternalLink = x["link"].GetAttribute("href");
                    }
                    if (x["category"] != null)
                    {
                        newItem.Type = x["category"].GetAttribute("term");
                    }
                    if (x["published"] != null)
                    {
                        newItem.Published = Sitecore.DateUtil.ToIsoDate(DateTime.Parse(x["published"].InnerText));
                    }
                    if (x["title"] != null)
                    {
                        newItem.Title = x["title"].InnerText;
                    }
                    if (x["summary"] != null)
                    {
                        newItem.Summary = x["summary"].InnerText;
                    }
                    if (x["csm:product"] != null)
                    {
                        if (x["csm:product"]["csm:references"] != null)
                        {
                            temp = x["csm:product"]["csm:references"].ChildNodes;
                            foreach (XmlNode t in temp)
                            {
                                if (t.Attributes["type"].InnerText == "itunes")
                                {
                                    newItem.AppleAppStoreID = t.InnerText;
                                }
                                else if (t.Attributes["type"].InnerText == "googleplay")
                                {
                                    newItem.GooglePlayStoreID = t.InnerText;
                                }
                            }
                        }

                        if (x["csm:product"]["csm:images"] != null)
                        {
                            temp = x["csm:product"]["csm:images"].ChildNodes;
                            List <ReviewImageModel> images = new List <ReviewImageModel>();
                            foreach (XmlNode t in temp)
                            {
                                if (t.Attributes["type"].InnerText == "screenshot")
                                {
                                    ReviewImageModel image = new ReviewImageModel();
                                    image.URL     = t.InnerText;
                                    image.Name    = newItem.Title + "-screenshot-" + (images.Count + 1).ToString();
                                    image.AltText = "Screenshot";
                                    images.Add(image);
                                }
                                else if (t.Attributes["type"].InnerText == "product")
                                {
                                    ReviewImageModel image = new ReviewImageModel();
                                    image.URL         = t.InnerText;
                                    image.Name        = newItem.Title + "-screenshot-" + (images.Count + 1).ToString();
                                    image.AltText     = "Screenshot";
                                    newItem.Thumbnail = image;
                                }
                            }

                            newItem.Screenshots = images;
                        }

                        if (x["csm:product"]["csm:platforms"] != null)
                        {
                            temp = x["csm:product"]["csm:platforms"].ChildNodes;
                            foreach (XmlNode t in temp)
                            {
                                newItem.Platforms += t.InnerText + ",";
                            }
                        }

                        if (x["csm:product"]["csm:prices"] != null && x["csm:product"]["csm:prices"]["csm:price"] != null)
                        {
                            newItem.Price = x["csm:product"]["csm:prices"]["csm:price"].InnerText;
                        }
                        if (x["csm:product"]["csm:genre"] != null)
                        {
                            newItem.Genres = x["csm:product"]["csm:genre"].InnerText;
                        }
                    }

                    if (x["csm:review"] != null)
                    {
                        newItem.QualityRank = x["csm:review"].GetAttribute("star_rating");
                        if (x["csm:review"]["csm:slider"] != null)
                        {
                            newItem.TargetGrade = ResolveGrade(x["csm:review"]["csm:slider"].GetAttribute("target_age"));
                            newItem.OffGrade    = ResolveGrade(x["csm:review"]["csm:slider"].GetAttribute("off_age"));
                            newItem.OnGrade     = ResolveGrade(x["csm:review"]["csm:slider"].GetAttribute("on_age"));
                        }
                        if (x["csm:review"]["csm:parents_need_to_know"] != null)
                        {
                            newItem.ParentsNeedToKnow = x["csm:review"]["csm:parents_need_to_know"].InnerText;
                        }
                        if (x["csm:review"]["csm:description"] != null)
                        {
                            newItem.Description = x["csm:review"]["csm:description"].InnerText;
                        }
                        if (x["csm:review"]["csm:any_good"] != null)
                        {
                            newItem.AnyGood = x["csm:review"]["csm:any_good"].InnerText;
                        }
                        if (x["csm:review"]["csm:learning_rating"] != null)
                        {
                            newItem.LearningRank = x["csm:review"]["csm:learning_rating"].GetAttribute("value");
                            if (x["csm:review"]["csm:learning_rating"]["csm:what_kids_can_learn"] != null)
                            {
                                newItem.WhatKidsCanLearn = x["csm:review"]["csm:learning_rating"]["csm:what_kids_can_learn"].InnerText;
                            }
                            if (x["csm:review"]["csm:learning_rating"]["csm:how_parents_help"] != null)
                            {
                                newItem.HowParentsCanHelp = x["csm:review"]["csm:learning_rating"]["csm:how_parents_help"].InnerText;
                            }

                            if (x["csm:review"]["csm:learning_rating"]["csm:subjects"] != null)
                            {
                                temp = x["csm:review"]["csm:learning_rating"]["csm:subjects"].ChildNodes;
                                foreach (XmlNode t in temp)
                                {
                                    newItem.Subjects += t.Attributes["name"].InnerText + ",";
                                }
                            }

                            if (x["csm:review"]["csm:learning_rating"]["csm:skills"] != null)
                            {
                                temp = x["csm:review"]["csm:learning_rating"]["csm:skills"].ChildNodes;
                                foreach (XmlNode t in temp)
                                {
                                    newItem.Skills += t.Attributes["name"].InnerText + ",";
                                }
                            }
                        }

                        if (x["csm:review"]["csm:special_needs"] != null)
                        {
                            temp = x["csm:review"]["csm:special_needs"].ChildNodes;
                            foreach (XmlNode t in temp)
                            {
                                newItem.Issues += t.Attributes["name"].InnerText + ",";
                            }

                            newItem.Category = x["csm:review"]["csm:special_needs"].GetAttribute("assistive");
                        }
                    }
                }
                catch (Exception e)
                {
                    Log += e.Message + "<br><br><b>";
                }

                try
                {
                    reviewManager.Add(newItem);
                    count++;
                }
                catch
                {
                }
            }

            return(count);
        }
Example #3
0
        public static void MigrateSurveyCustomer()
        {
            PortalDbContext portalDbContext = new PortalDbContext();
            PortalDbRepository<Access> accesPortalDbRepository = new PortalDbRepository<Access>(portalDbContext);
            PortalDbRepository<SurveyCustomer> surveyCustomerRepository = new PortalDbRepository<SurveyCustomer>(portalDbContext);
            PortalDbRepository<SurveyQuestion> surveyQuestionRepository = new PortalDbRepository<SurveyQuestion>(portalDbContext);
            PortalDbRepository<SurveysGeneralAnswer> surveysGeneralAnswerRepository = new PortalDbRepository<SurveysGeneralAnswer>(portalDbContext);
            PortalDbRepository<SurveysPossibleAnswer> surveyPossibleAnswerRepository = new PortalDbRepository<SurveysPossibleAnswer>(portalDbContext);

            Manager portalDbManager = new Manager(accesPortalDbRepository);
            /////////////===================>>>>>>>>>>>>>>>>>>>
            SurveyCustomerDbManager SurveyCustomerDbManager = new SurveyCustomerDbManager(surveyCustomerRepository, portalDbManager);
            SurveyQuestionManager SurveyQuestionManager = new SurveyQuestionManager(surveyQuestionRepository, portalDbManager);
            SurveyGeneralAnswerManager SurveyGeneralAnswerManager = new SurveyGeneralAnswerManager(surveysGeneralAnswerRepository, portalDbManager);
            SurveyPossibleAnswerManager SurveyPossibleAnswerManager = new SurveyPossibleAnswerManager(surveyPossibleAnswerRepository, portalDbManager);

            //////////////////////////////////////////////////
            CosmeticExpressDbContext cosmeticExpressDbContext = new CosmeticExpressDbContext();
            CosmeticExpressDbRepository<Access> accesCosmeticExpressDbRepository = new CosmeticExpressDbRepository<Access>(cosmeticExpressDbContext);
            CosmeticExpressDbRepository<User> userRepository = new CosmeticExpressDbRepository<User>(cosmeticExpressDbContext);
            CosmeticExpressDbRepository<Schedule> scheduleRepository = new CosmeticExpressDbRepository<Schedule>(cosmeticExpressDbContext);
            CosmeticExpressDbRepository<Office> officeRepository = new CosmeticExpressDbRepository<Office>(cosmeticExpressDbContext);
            CosmeticExpressDbRepository<VWCompleteSurgery> VWCompleteSurgeryRepository = new CosmeticExpressDbRepository<VWCompleteSurgery>(cosmeticExpressDbContext);
            CosmeticExpressDbRepository<Entity.CosmeticExpress.Patient> CosmeticExpressPatientRepository = new CosmeticExpressDbRepository<Entity.CosmeticExpress.Patient>(cosmeticExpressDbContext);


            Manager cosmeticExpressDbManager = new Manager(accesCosmeticExpressDbRepository);
            UserManager userManager = new UserManager(userRepository, cosmeticExpressDbManager);
            ScheduleManager scheduleManager = new ScheduleManager(scheduleRepository, cosmeticExpressDbManager);
            OfficeManager officeManager = new OfficeManager(officeRepository, cosmeticExpressDbManager);
            VWCompleteSurgeryManager vwCompleteSurgeryManager = new VWCompleteSurgeryManager(VWCompleteSurgeryRepository, cosmeticExpressDbManager);
            CosmeticExpressPatientManager CosmeticExpressPatientManager = new CosmeticExpressPatientManager(CosmeticExpressPatientRepository, cosmeticExpressDbManager);

            //////////////////////////////////////////////////
            ApplicationDbContext applicationDbContext = new ApplicationDbContext();
            ApplicationDbRepository<Access> accesApplicationDbRepository = new ApplicationDbRepository<Access>(applicationDbContext);
            ApplicationDbRepository<Review> reviewRepository = new ApplicationDbRepository<Review>(applicationDbContext);
            ApplicationDbRepository<Doctor> doctorRepository = new ApplicationDbRepository<Doctor>(applicationDbContext);
            ApplicationDbRepository<Lead> leadRepository = new ApplicationDbRepository<Lead>(applicationDbContext);
            ApplicationDbRepository<Expert> expertRepository = new ApplicationDbRepository<Expert>(applicationDbContext);
            ApplicationDbRepository<Center> centerRepository = new ApplicationDbRepository<Center>(applicationDbContext);
            ApplicationDbRepository<Entity.ReviewManagerEntities.Patient> ApplicationPatientRepository = new ApplicationDbRepository<Entity.ReviewManagerEntities.Patient>(applicationDbContext);


            Manager applicationDbManager = new Manager(accesApplicationDbRepository);
            ReviewManager reviewManager = new ReviewManager(reviewRepository, applicationDbManager);
            ///////////////////=============================>>>>>>>>>>>>>>>
            DoctorManager doctorManager = new DoctorManager(doctorRepository, applicationDbManager);
            LeadManager leadManager = new LeadManager(leadRepository, applicationDbManager);
            ExpertManager expertManager = new ExpertManager(expertRepository, applicationDbManager);
            CenterManager centerManager = new CenterManager(centerRepository, applicationDbManager);
            ApplicationPatientManager ApplicationPatientManager = new ApplicationPatientManager(ApplicationPatientRepository, cosmeticExpressDbManager);

            var SurveyQuestionCollection = SurveyQuestionManager.Get().ToArray();
            var SurveyCustomerCollection = SurveyCustomerDbManager.Get().ToArray();
            var SurveyPossibleAnswerCollection = SurveyPossibleAnswerManager.Get().ToArray();
            var SurveyGeneralAnswerCollection = SurveyGeneralAnswerManager.Get().ToArray();
            ICollection<VWCompleteSurgery> vwCompleteSurgeriesCollection = vwCompleteSurgeryManager.Get().ToArray();

            var doctors = doctorManager.Get().Select(d => new{ d.Id, d.FullName, d.Reviews.Count }).ToArray();
            var sources = reviewManager.Get().GroupBy(r => r.Source).ToArray().Select(group => new {Source = group.Key, Count = group.Count()});

            ICollection<Review> ReviewCollection = new List<Review>();

            foreach (var sgAnswer in SurveyGeneralAnswerCollection)
            {
                if (!reviewManager.Get().Any(review => review.ExternalId == sgAnswer.Id && review.Source == "Portal") && sgAnswer.SurveyTemplateId == 2)
                {
                    //Schedule Schedule = scheduleManager.Get(sched =>
                    //sched.PatientID == sgAnswer.SurveyCustomer.ExternalId
                    //&& sched.ServiceID == 5
                    //&& sched.dtStart.AddMonths(3) >= sgAnswer.SurveyDate).FirstOrDefault();

                    VWCompleteSurgery surgery = vwCompleteSurgeriesCollection.Where(surg => surg.PatientID == sgAnswer.SurveyCustomer.ExternalId && surg.dtStart.AddMonths(3) >= sgAnswer.SurveyDate).FirstOrDefault();


                    if (surgery != null)
                    {
                        Review review = new Review();
                        review.Source = "Portal";
                        review.ExternalId = sgAnswer.Id;
                        review.Rating = 0;

                        review.CreatedOn = surgery.dtStart;

                        //FROM CEXPRESS/Patient/Patient
                        Entity.CosmeticExpress.Patient CosmeticExpressPatient = CosmeticExpressPatientManager.Get(patient => patient.PatientID == surgery.PatientID).FirstOrDefault();
                        var existingApplicationPatient = ApplicationPatientManager.Get(patient => patient.ExternalId == CosmeticExpressPatient.PatientID && patient.Source == "CosmeticExpress").FirstOrDefault();
                        if (existingApplicationPatient != null)
                        {
                            review.PatientId = existingApplicationPatient.Id;
                        }
                        else
                        {
                            Entity.ReviewManagerEntities.Patient Patient = new Entity.ReviewManagerEntities.Patient()
                            {
                                ExternalId = CosmeticExpressPatient.PatientID,
                                FirstName = CosmeticExpressPatient.FirstName,
                                LastName = CosmeticExpressPatient.LastName,
                                MiddleName = CosmeticExpressPatient.MiddleName,
                                DOB = CosmeticExpressPatient.DOB,
                                Email = CosmeticExpressPatient.Email,
                                Source = "CosmeticExpress"
                            };
                            review.Patient = Patient;
                        }


                        //FROM CEXPRESS/USER TO APP/DOCTOR 
                        User User = userManager.Get(user => user.UserID == surgery.ProviderUserID).FirstOrDefault();
                        var existingDoctorinDb = doctorManager.Get(doc => doc.ExternalId == User.UserID && doc.Source == "CosmeticExpress").FirstOrDefault();
                        var reviewInCollectionWithSameDoctor = ReviewCollection.FirstOrDefault(rev => rev.Doctor != null && rev.Doctor.ExternalId == User.UserID && rev.Doctor.Source == "CosmeticExpress");
                        if (existingDoctorinDb != null)
                        {
                            review.DoctorId = existingDoctorinDb.Id;
                        }
                        else
                        {
                            if (reviewInCollectionWithSameDoctor != null)
                            {
                                review.Doctor = reviewInCollectionWithSameDoctor.Doctor;
                            }
                        }
                        if (review.Doctor == null && review.DoctorId == null)
                        {
                            {
                                Doctor Doctor = new Doctor()
                                {
                                    FullName = User.FullName,
                                    Source = "CosmeticExpress",
                                    ExternalId = User.UserID
                                };
                                review.Doctor = Doctor;
                            }
                        }

                        //FROM CEXPRESS/OFFICE TO APP/CENTER 
                        Office Office = officeManager.Get(office => office.OfficeId == surgery.OfficeID).FirstOrDefault();

                        var existingCenterinDb = centerManager.Get(center => center.ExternalId == surgery.OfficeID).FirstOrDefault();
                        var centerInCollectionWithSameDoctor = ReviewCollection.FirstOrDefault(rev => rev.Center != null && rev.Center.ExternalId == Office.OfficeId && rev.Center.Source == "CosmeticExpress");

                        if (existingCenterinDb != null)
                        {
                            review.CenterId = existingCenterinDb.Id;
                        }
                        else
                        {
                            if (centerInCollectionWithSameDoctor != null)
                            {
                                review.Center = centerInCollectionWithSameDoctor.Center;
                            }
                        }
                        if (review.Center == null && review.CenterId == null)
                        {
                            Center Center = new Center()
                            {
                                Name = Office.OfficeName,
                                Source = "CosmeticExpress",
                                ExternalId = Office.OfficeId
                            };
                            review.Center = Center;                           
                        }

                        //Recorriendo cada pregunta dentro del survey para calcular el rating
                        foreach (var answer in sgAnswer.SurveysAnswers)
                        {
                            if (SurveyQuestionCollection.FirstOrDefault(q => q.Id == answer.SurveyQuestionId).QuestionType == "edit")
                            {
                                review.Text = answer.Answer != null ? answer.Answer.ToString() : "Empty";
                            }
                            else
                            {
                                var anwersItem = SurveyPossibleAnswerCollection.FirstOrDefault(spa => spa.Id == answer.SurveysPossibleAnswerId);
                                review.Rating += anwersItem != null ? anwersItem.Weight : 0;
                            }
                        }
                        //anadiento el review a la coleccion
                        ReviewCollection.Add(review);
                    }
                }
            }
            //from ReviewCollection to reviewManager
            foreach (var review in ReviewCollection)
            {
                reviewManager.Add(review);               
            }
            reviewManager.SaveChanges();
        }