Пример #1
0
        internal bool SaveCustomizeData(CustomizeData data)
        {
            if (data.UnitId <= 0)
            {
                throw new ArgumentException("unit is not defined");
            }

            int sortOrder   = 0;
            var stageIds    = new List <int>();
            var dataService = new QNomyDataService();

            if (data.ConfigId <= 0)
            {
                data.ConfigId = dataService.InsertConfigId(data.UnitId);
            }

            dataService.DeleteCalendarStageServices(data.ConfigId);
            var dataNotShownStage = dataService.GetClendarStageByType(data.ConfigId, CalendarStageType.None);

            if (dataNotShownStage == null)
            {
                dataNotShownStage = new CalendarStage()
                {
                    Name = "None", StageType = CalendarStageType.None, CalendarStageConfigId = data.ConfigId
                };
                dataNotShownStage.Id = dataService.InserCalendarStage(dataNotShownStage);
            }

            stageIds.Add(dataNotShownStage.Id);
            dataService.InsertCalendarStageServices(dataNotShownStage.Id, data.NotShownServices);

            foreach (var stage in data.Stages)
            {
                sortOrder++;
                stage.SortOrder = sortOrder;
                dataService.UpdateOrInsertStage(data.ConfigId, stage);
                stageIds.Add(stage.Id);
            }


            dataService.DeleteCalendarStagesExcept(data.ConfigId, stageIds);

            return(true);
        }