Esempio n. 1
0
 public SurveyBaseVm(AdminLevel a, SurveyDetails s, ICalcIndicators c)
 {
     r = new SurveyRepository();
     this.model = r.GetById(s.Id);
     adminLevel = a;
     calc = c;
 }
 public IView GetSurvey(SurveyDetails details)
 {
     return new DataEntryEdit(new SurveyBaseVm(adminLevel, details, new CalcSurvey()));
 }
 public void Delete(SurveyDetails details, int userId) { surveys.Delete(details, userId); }
        private SurveyBase SplitSurveys(SurveyDetails details, AdminLevel source, List<AdminLevelAllocation> dests, int redistrictId, OleDbCommand command, 
            OleDbConnection connection, Dictionary<int, SentinelSite> newSites)
        {
            var oldSurvey = surveyRepo.GetById(details.Id);

            // make new
            var newForm = Util.DeepClone(oldSurvey);
            // save old with only original unit
            oldSurvey.Notes += string.Format(Translations.RedistrictSurveyNote, string.Join(", ", oldSurvey.AdminLevels.Select(s => s.Name).ToArray()));
            oldSurvey.AdminLevels = new List<AdminLevel> { source };
            surveyRepo.SaveSurveyBase(command, connection, oldSurvey, userId);

            // add new units
            // We used to make sure it didn't exist in the destination yet? dont get it, must be split combine... if (!newForm.AdminLevels.Select(a => a.Id).Contains(dest.Id))
            newForm.Id = 0;
            newForm.IsRedistricted = true;
            newForm.AdminLevels.RemoveAll(a => a.Id == source.Id);
            newForm.AdminLevels.AddRange(dests.Select(a => a.Unit));
            if (oldSurvey.SentinelSiteId.HasValue && oldSurvey.SentinelSiteId > 0)
            {
                if (!newSites.ContainsKey(oldSurvey.SentinelSiteId.Value))
                {  
                    var oldSite = surveyRepo.GetSiteById(oldSurvey.SentinelSiteId.Value);
                    CloneSite(source, dests, command, connection, newSites, oldSite);
                }
                newForm.SentinelSiteId = newSites[oldSurvey.SentinelSiteId.Value].Id;
            }

            surveyRepo.SaveSurveyBase(command, connection, newForm, userId);
            demoRepo.InsertRedistrictForm(command, connection, userId, redistrictId, oldSurvey.Id, newForm.Id, IndicatorEntityType.Survey);
            
            return newForm;
        }