public static List <ConfigurationSection> GetWebServerSections(Site site, string path, string configScope = null)
        {
            if (site != null && path == null)
            {
                throw new ArgumentNullException("path");
            }

            // Get the location to be used when getting sections from the configuration
            string location = site == null ? null : ManagementUnit.GetLocationTag(site.Id, path, configScope);

            // Get the target configuration file using configScope
            Configuration configuration = ManagementUnit.GetConfiguration(site?.Id, path, configScope);;


            List <ConfigurationSection> sectionList = new List <ConfigurationSection>();

            SectionGroup webServerGroup = configuration.GetEffectiveSectionGroup().SectionGroups.FirstOrDefault(group => group.Name.Equals(XPATH));

            if (webServerGroup == null)
            {
                return(sectionList);
            }

            FillWithSubSections(sectionList, webServerGroup, webServerGroup.Name, configuration, location);

            return(sectionList);
        }
 public void AddSectionGroup(SectionGroup sectionGroup)
 {
     if (!m_sections.Contains(sectionGroup))
     {
         m_sections.Add(sectionGroup);
     }
 }
Exemple #3
0
        public async Task <SectionGroup> InsertSectionGroup(SectionGroup group)
        {
            var id = (int)await _connection.InsertAsync(group);

            group.Id = id;
            return(group);
        }
Exemple #4
0
 public IActionResult Edit(SectionGroup sectionGroup)
 {
     if (ModelState.IsValid)
     {
         sectionGroupService.Save(sectionGroup);
         return(RedirectToAction("Index"));
     }
     ViewData["SurveyTemplateId"] = sectionGroup.SurveyTemplateId;
     return(View(sectionGroup));
 }
Exemple #5
0
 public IActionResult Create(SectionGroup sectionGroup)
 {
     if (ModelState.IsValid)
     {
         sectionGroup.Id = new int();
         sectionGroupService.Save(sectionGroup);
         return(RedirectToAction("Index"));
     }
     ViewData["SurveyTemplateId"] = sectionGroup.SurveyTemplateId;//TODO make selectlist?
     return(View(sectionGroup));
 }
        private SectionGroup GetSectionGroup(Grade grade, Section section)
        {
            GradeGroup gradeGroup = GetGradeGroup(grade);

            if (gradeGroup == null)
            {
                return(null);
            }

            SectionGroup sectionGroup = gradeGroup.GetSectionGroup(section);

            return(sectionGroup);
        }
        private Schedule Internal_GetSchedule(Grade grade, int section, int index)
        {
            SectionGroup sectionGroup = GetSectionGroup(grade, section);

            if (sectionGroup == null)
            {
                return(null);
            }
            else
            {
                return(sectionGroup.GetSchedule(index));
            }
        }
        private static IEnumerable <TreeItem> MakeChildren(SectionGroup group)
        {
            int index = 0;

            foreach (var sg in group.SectionGroup1 ?? Enumerable.Empty <SectionGroup>())
            {
                yield return(new SectionGroupTreeItem(sg, index++));
            }

            foreach (var s in group.Section ?? Enumerable.Empty <Section>())
            {
                yield return(new SectionTreeItem(s, index++));
            }
        }
        public void AddSchedule(Grade grade, Section section, List <Schedule> schedules)
        {
            GradeGroup   gradeGroup   = GetGradeGroup(grade);
            SectionGroup sectionGroup = new SectionGroup(section, schedules);

            if (gradeGroup != null)
            {
                gradeGroup.AddSectionGroup(sectionGroup);
            }
            else
            {
                Debug.Log("Failed to add schedule.");
            }
        }
Exemple #10
0
        // GET: SectionGroups/Details/5
        public IActionResult Details(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            SectionGroup sectionGroup = sectionGroupService.GetById(id.Value);

            if (sectionGroup == null)
            {
                return(HttpNotFound());
            }

            return(View(sectionGroup));
        }
Exemple #11
0
        // GET: SectionGroups/Edit/5
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            SectionGroup sectionGroup = sectionGroupService.GetById(id.Value);

            if (sectionGroup == null)
            {
                return(HttpNotFound());
            }
            ViewData["SurveyTemplateId"] = sectionGroup.SurveyTemplateId;
            return(View(sectionGroup));
        }
 public ActionResult Save(SectionGroup group)
 {
     if (!ModelState.IsValid)
     {
         return(View("Form", group));
     }
     if (group.ActionType == ActionType.Create)
     {
         _sectionGroupService.Add(group);
     }
     else
     {
         _sectionGroupService.Update(group);
     }
     ViewBag.Close = true;
     return(View("Form", group));
 }
 public ActionResult Save(SectionGroup group)
 {
     if (!ModelState.IsValid)
     {
         return View("Form", group);
     }
     if (group.ActionType == ActionType.Create)
     {
         _sectionGroupService.Add(group);
     }
     else
     {
         _sectionGroupService.Update(group);
     }
     ViewBag.Close = true;
     return View("Form", group);
 }
        private string[] Internal_GetScheduleItems(Grade grade, int section)
        {
            SectionGroup sectionGroup = GetSectionGroup(grade, section);

            if (sectionGroup == null)
            {
                return(null);
            }

            List <string> schedules = new List <string>();

            for (int i = 0; i < sectionGroup.scheduleCount; i++)
            {
                schedules.Add(sectionGroup.GetSchedule(i).name.Replace(" Schedule", ""));
            }

            return(schedules.ToArray());
        }
        public Holland2PathToCircleConverter(XElement root) : base(root)
        {
            SectionGroups = new List <SectionGroup>();

            var sg = new SectionGroup {
                Id = "Orchestra", Sections = new List <Section>()
            };

            sg.Sections.Add(new Section {
                Id = "Left", AddRadius = false
            });
            sg.Sections.Add(new Section {
                Id = "Center", AddRadius = false
            });
            sg.Sections.Add(new Section {
                Id = "Right", AddRadius = true
            });
            SectionGroups.Add(sg);

            sg = new SectionGroup {
                Id = "OrchestraBoxes", Sections = new List <Section>()
            };
            sg.Sections.Add(new Section {
                Id = "BoxC", AddRadius = false
            });
            sg.Sections.Add(new Section {
                Id = "BoxH", AddRadius = true
            });
            SectionGroups.Add(sg);

            sg = new SectionGroup {
                Id = "OrchestraCircle", Sections = new List <Section>()
            };
            sg.Sections.Add(new Section {
                Id = "Left", AddRadius = false
            });
            sg.Sections.Add(new Section {
                Id = "Center", AddRadius = false
            });
            sg.Sections.Add(new Section {
                Id = "Right", AddRadius = true
            });
            SectionGroups.Add(sg);
        }
        /// <summary>
        /// Update the navigation property sectionGroups in users
        /// <param name="body"></param>
        /// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
        /// </summary>
        public RequestInformation CreatePatchRequestInformation(SectionGroup body, Action <SectionGroupItemRequestBuilderPatchRequestConfiguration> requestConfiguration = default)
        {
            _ = body ?? throw new ArgumentNullException(nameof(body));
            var requestInfo = new RequestInformation {
                HttpMethod     = Method.PATCH,
                UrlTemplate    = UrlTemplate,
                PathParameters = PathParameters,
            };

            requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
            if (requestConfiguration != null)
            {
                var requestConfig = new SectionGroupItemRequestBuilderPatchRequestConfiguration();
                requestConfiguration.Invoke(requestConfig);
                requestInfo.AddRequestOptions(requestConfig.Options);
                requestInfo.AddHeaders(requestConfig.Headers);
            }
            return(requestInfo);
        }
            public SectionGroup GetSectionGroup(Section section)
            {
                if (m_sections == null || m_sections.Count == 0)
                {
                    return(null);
                }

                SectionGroup sectionGroup = null;

                foreach (SectionGroup s in m_sections)
                {
                    if (s.section == section)
                    {
                        sectionGroup = s;
                        break;
                    }
                }

                return(sectionGroup);
            }
        public Holland2PathToCircleConverter(XElement root) : base(root)
        {
            SectionGroups = new List<SectionGroup>();

            var sg = new SectionGroup {Id = "Orchestra", Sections = new List<Section>()};
            sg.Sections.Add(new Section { Id = "Left", AddRadius = false });
            sg.Sections.Add(new Section { Id = "Center", AddRadius = false });
            sg.Sections.Add(new Section { Id = "Right", AddRadius = true });
            SectionGroups.Add(sg);

            sg = new SectionGroup { Id = "OrchestraBoxes", Sections = new List<Section>() };
            sg.Sections.Add(new Section { Id = "BoxC", AddRadius = false });
            sg.Sections.Add(new Section { Id = "BoxH", AddRadius = true });
            SectionGroups.Add(sg);

            sg = new SectionGroup { Id = "OrchestraCircle", Sections = new List<Section>() };
            sg.Sections.Add(new Section { Id = "Left", AddRadius = false });
            sg.Sections.Add(new Section { Id = "Center", AddRadius = false });
            sg.Sections.Add(new Section { Id = "Right", AddRadius = true });
            SectionGroups.Add(sg);
        }
        private void CheckIISConfigurationFile()
        {
            bool flag  = false;
            bool flag2 = false;

            using (ServerManager serverManager = new ServerManager())
            {
                Site site = serverManager.Sites[base.DefaultSiteName];
                if (serverManager.ApplicationPools["MSExchangePowerShellAppPool"] == null)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorPowerShellVdirAppPoolNotExist("MSExchangePowerShellAppPool", base.IISConfigFilePath)), ErrorCategory.InvalidOperation, null);
                }
                if (site.Applications["/PowerShell"] == null)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorApplicationNotExist("PowerShell", base.IISConfigFilePath)), ErrorCategory.InvalidOperation, null);
                }
                if (site.Applications["/PowerShell"].VirtualDirectories["/"] == null)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorVdirNotExisted("PowerShell", base.IISConfigFilePath)), ErrorCategory.InvalidOperation, null);
                }
                if (this.DataCenterCAS)
                {
                    if (site.Applications["/PowerShell-LiveID"] == null)
                    {
                        base.WriteError(new InvalidOperationException(Strings.ErrorApplicationNotExist("PowerShell-LiveID", base.IISConfigFilePath)), ErrorCategory.InvalidOperation, null);
                    }
                    if (site.Applications["/PowerShell-LiveID"].VirtualDirectories["/"] == null)
                    {
                        base.WriteError(new InvalidOperationException(Strings.ErrorVdirNotExisted("PowerShell-LiveID", base.IISConfigFilePath)), ErrorCategory.InvalidOperation, null);
                    }
                }
                bool flag3 = false;
                for (int i = 0; i < site.Bindings.Count; i++)
                {
                    Binding binding = site.Bindings[i];
                    if (string.Equals("https", binding.Protocol, StringComparison.InvariantCultureIgnoreCase))
                    {
                        flag3 = true;
                        break;
                    }
                }
                if (!flag3)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorHttpsBindingNotExist(base.IISConfigFilePath)), ErrorCategory.InvalidOperation, null);
                }
                SectionGroup      sectionGroup      = serverManager.GetApplicationHostConfiguration().RootSectionGroup.SectionGroups["system.webServer"];
                SectionDefinition sectionDefinition = sectionGroup.Sections["system.management.wsmanagement.config"];
                if (sectionDefinition == null)
                {
                    base.BackupIISConfig();
                    base.WriteVerbose(Strings.VerboseAddWSManConfigSection(base.IISConfigFilePath));
                    sectionDefinition = sectionGroup.Sections.Add("system.management.wsmanagement.config");
                    sectionDefinition.OverrideModeDefault = "Allow";
                }
                else if (!string.Equals(sectionDefinition.OverrideModeDefault, "Allow", StringComparison.InvariantCultureIgnoreCase))
                {
                    base.BackupIISConfig();
                    sectionDefinition.OverrideModeDefault = "Allow";
                }
                ConfigurationElementCollection collection           = serverManager.GetApplicationHostConfiguration().GetSection("system.webServer/globalModules").GetCollection();
                ConfigurationElement           configurationElement = null;
                for (int j = 0; j < collection.Count; j++)
                {
                    ConfigurationElement configurationElement2 = collection[j];
                    object attributeValue = configurationElement2.GetAttributeValue("name");
                    if (attributeValue != null && string.Equals("WSMan", attributeValue.ToString(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        configurationElement = configurationElement2;
                        break;
                    }
                }
                if (configurationElement == null)
                {
                    flag2 = true;
                }
                else
                {
                    object value = configurationElement.Attributes["image"].Value;
                    if (value == null || !string.Equals(value.ToString(), base.WSManModuleFilePath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        flag = true;
                    }
                }
                if (base.IISBackupFileName != null)
                {
                    serverManager.CommitChanges();
                }
            }
            if (flag || flag2)
            {
                base.BackupIISConfig();
            }
            if (flag)
            {
                string arguments = "uninstall module WSMan";
                base.WriteVerbose(Strings.VerboseUninstallWSManModule("WSMan"));
                base.ExecuteCmd(base.AppcmdPath, arguments, base.InetsrvPath, true, true);
            }
            if (flag2)
            {
                string arguments2 = "unlock config -section:system.webServer/modules";
                base.WriteVerbose(Strings.VerboseUnlockingModulesSection);
                base.ExecuteCmd(base.AppcmdPath, arguments2, base.InetsrvPath, true, true);
                arguments2 = "install module /name:WSMan /image:" + base.WSManModuleFilePath + " /add:false";
                base.WriteVerbose(Strings.VerboseInstallWSManModule("WSMan"));
                base.ExecuteCmd(base.AppcmdPath, arguments2, base.InetsrvPath, true, true);
            }
        }
        public JsonResult UploadTemplate()
        {
            if (Request.Files.Count > 0)
            {
                try
                {
                    var             file       = Request.Files[0];
                    ZipFile         zipFile    = new ZipFile();
                    var             files      = zipFile.ToFileCollection(file.InputStream);
                    SectionTemplate template   = null;
                    bool            asTemplate = false;
                    foreach (ZipFileInfo item in files)
                    {
                        if (item.RelativePath.EndsWith(".cshtml"))
                        {
                            using (
                                var fs = System.IO.File.Create(Server.MapPath("~/Modules/Section/Views") + item.RelativePath)
                                )
                            {
                                fs.Write(item.FileBytes, 0, item.FileBytes.Length);
                            }
                        }
                        else
                        {
                            using (
                                var fs =
                                    System.IO.File.Create(Server.MapPath("~/Modules/Section/Views/Thumbnail") +
                                                          item.RelativePath))
                            {
                                fs.Write(item.FileBytes, 0, item.FileBytes.Length);
                            }
                            if (item.RelativePath.EndsWith(".json"))
                            {
                                var info = System.IO.File.ReadAllText(Server.MapPath("~/Modules/Section/Views/Thumbnail") +
                                                                      item.RelativePath);
                                template = Newtonsoft.Json.JsonConvert.DeserializeObject <SectionTemplate>(info);
                                var sectionTemplateService =
                                    ServiceLocator.Current.GetInstance <ISectionTemplateService>();
                                if (sectionTemplateService.Count(m => m.TemplateName == template.TemplateName) > 0)
                                {
                                    sectionTemplateService.Update(template);
                                }
                                else
                                {
                                    sectionTemplateService.Add(template);
                                }
                            }
                            else if (item.RelativePath.EndsWith(".xml"))
                            {
                                asTemplate = true;
                            }
                        }
                    }
                    if (asTemplate && template != null)
                    {
                        SectionWidget widget = new SectionWidget
                        {
                            IsTemplate        = true,
                            WidgetName        = template.Title,
                            PartialView       = "Widget.Section",
                            AssemblyName      = "Easy.CMS.Section",
                            ServiceTypeName   = "Easy.CMS.Section.Service.SectionWidgetService",
                            ViewModelTypeName = "Easy.CMS.Section.Models.SectionWidget",
                            FormView          = "SectionWidgetForm",
                            IsSystem          = false,
                            Thumbnail         = "~/Modules/Section/Views/" + template.Thumbnail
                        };
                        widget.Thumbnail = widget.Thumbnail.Replace("\\", "/");
                        SectionGroup group = new SectionGroup();
                        group.PartialView = template.TemplateName;
                        _sectionGroupService.GenerateContentFromConfig(group);
                        widget.Groups = new List <SectionGroup> {
                            group
                        };
                        ServiceLocator.Current.GetInstance <ISectionWidgetService>().Add(widget);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                    return(Json(new AjaxResult {
                        Status = AjaxStatus.Error, Message = "上传的模板不正确"
                    }));
                }
            }

            return(Json(new AjaxResult {
                Status = AjaxStatus.Normal, Message = "上传成功"
            }));
        }
Exemple #21
0
        public SectionGroupTreeItem(SectionGroup sectionGroup, int index) : base(sectionGroup.ID, index, MakeChildren(sectionGroup))
        {
            _sectionGroup = sectionGroup ?? throw new ArgumentNullException(nameof(sectionGroup));

            Title = sectionGroup.name;
        }
Exemple #22
0
 public async Task UpdateSectionGroup(SectionGroup sectionGroup)
 {
     await _connection.UpdateAsync(sectionGroup);
 }
Exemple #23
0
 public async Task DeleteSectionGroup(SectionGroup sectionGroup)
 {
     await _connection.DeleteAsync(sectionGroup);
 }
        private static void FillWithSubSections(List <ConfigurationSection> sectionList, SectionGroup group, string groupXPath, Configuration configuration, string location)
        {
            foreach (SectionDefinition section in group.Sections)
            {
                var sectionPath           = $"{groupXPath}/{section.Name}";
                ConfigurationSection sect = null;

                try {
                    sect = location == null?configuration.GetSection(sectionPath) : configuration.GetSection(sectionPath, location);
                }
                catch (FileLoadException e) {
                    throw new LockedException(sectionPath, e);
                }

                sectionList.Add(sect);
            }

            foreach (SectionGroup subGroup in group.SectionGroups)
            {
                FillWithSubSections(sectionList, subGroup, $"{groupXPath}/{subGroup.Name}", configuration, location);
            }
        }
Exemple #25
0
        /// <summary>
        /// create a training plan in the designated patrol, clone the designated plan contents if specified
        /// specified plan can be from any patrol, relevant skills/levels will be copied to target patrol as needed
        /// </summary>
        /// <param name="name"></param>
        /// <param name="patrolId"></param>
        /// <param name="copyFromPlanId"></param>
        /// <returns></returns>
        public async Task <Plan> CreatePlan(string name, int patrolId, int?copyFromPlanId)
        {
            Plan copyFromPlan = null;

            if (copyFromPlanId.HasValue)
            {
                copyFromPlan = await _planRepository.GetPlan(copyFromPlanId.Value);
            }

            var newPlan = new Plan()
            {
                PatrolId = patrolId
            };

            if (!string.IsNullOrEmpty(name))
            {
                newPlan.Name = name;
            }
            else if (copyFromPlan != null)
            {
                newPlan.Name = "Copy of " + copyFromPlan.Name;
            }
            else
            {
                newPlan.Name = "New Training Plan";
            }
            await _planRepository.InsertPlan(newPlan);

            var patrolLevels = (await _planRepository.GetLevels(patrolId)).ToList();
            var patrolSkills = (await _planRepository.GetSkills(patrolId)).ToList();
            var patrolGroups = (await _groupRepository.GetGroupsForPatrol(patrolId)).ToList();

            if (copyFromPlanId.HasValue)
            {
                var sections = await _planRepository.GetSectionsForPlan(copyFromPlanId.Value);

                var sectionSkills = await _planRepository.GetSectionSkillsForPlan(copyFromPlanId.Value);

                var sectionLevels = await _planRepository.GetSectionLevelsForPlan(copyFromPlanId.Value);

                var sectionGroups = await _planRepository.GetSectionGroupsForPlan(copyFromPlanId.Value);

                foreach (var section in sections)
                {
                    var newSection = new Section()
                    {
                        Name     = section.Name,
                        PatrolId = section.PatrolId,
                        Color    = section.Color
                    };
                    await _planRepository.InsertSection(newSection);

                    var planSection = new PlanSection()
                    {
                        PlanId    = newPlan.Id,
                        SectionId = newSection.Id
                    };
                    await _planRepository.InsertPlanSection(planSection);

                    var levels = sectionLevels.Where(x => x.SectionId == section.Id);
                    foreach (var sectionLevel in levels)
                    {
                        int levelId;
                        if (sectionLevel.Level.PatrolId == patrolId)
                        {
                            levelId = sectionLevel.Level.Id;
                        }
                        else
                        {
                            if (patrolLevels.Any(x => x.Name == sectionLevel.Level.Name))
                            {
                                levelId = patrolLevels.First(x => x.Name == sectionLevel.Level.Name).Id;
                            }
                            else
                            {
                                var newLevel = new Level()
                                {
                                    Name        = sectionLevel.Level.Name,
                                    Description = sectionLevel.Level.Description,
                                    PatrolId    = patrolId
                                };
                                await _planRepository.InsertLevel(newLevel);

                                patrolLevels.Add(newLevel);
                                levelId = newLevel.Id;
                            }
                        }

                        var newSectionLevel = new SectionLevel()
                        {
                            ColumnIndex = sectionLevel.ColumnIndex,
                            LevelId     = levelId,
                            SectionId   = newSection.Id
                        };
                        await _planRepository.InsertSectionLevel(newSectionLevel);
                    }

                    var skills = sectionSkills.Where(x => x.SectionId == section.Id);
                    foreach (var sectionSkill in skills)
                    {
                        int skillId;
                        if (sectionSkill.Skill.PatrolId == patrolId)
                        {
                            skillId = sectionSkill.Skill.Id;
                        }
                        else
                        {
                            if (patrolSkills.Any(x => x.Name == sectionSkill.Skill.Name))
                            {
                                skillId = patrolSkills.First(x => x.Name == sectionSkill.Skill.Name).Id;
                            }
                            else
                            {
                                var newSkill = new Skill()
                                {
                                    Name        = sectionSkill.Skill.Name,
                                    Description = sectionSkill.Skill.Description,
                                    PatrolId    = patrolId
                                };
                                await _planRepository.InsertSkill(newSkill);

                                patrolSkills.Add(newSkill);
                                skillId = newSkill.Id;
                            }
                        }

                        var newSectionSkill = new SectionSkill()
                        {
                            RowIndex  = sectionSkill.RowIndex,
                            SkillId   = skillId,
                            SectionId = newSection.Id
                        };
                        await _planRepository.InsertSectionSkill(newSectionSkill);
                    }

                    var groups = sectionGroups.Where(x => x.SectionId == section.Id);
                    foreach (var sectionGroup in groups)
                    {
                        int groupid;
                        if (sectionGroup.Group.PatrolId == patrolId)
                        {
                            groupid = sectionGroup.Group.Id;
                        }
                        else
                        {
                            if (patrolGroups.Any(x => x.Name == sectionGroup.Group.Name))
                            {
                                groupid = patrolGroups.First(x => x.Name == sectionGroup.Group.Name).Id;
                            }
                            else
                            {
                                var newGroup = new Group()
                                {
                                    PatrolId = patrolId,
                                    Name     = sectionGroup.Group.Name
                                };
                                await _groupRepository.InsertGroup(newGroup);

                                patrolGroups.Add(newGroup);
                                groupid = newGroup.Id;
                            }
                        }

                        var newSectionGroup = new SectionGroup()
                        {
                            SectionId = newSection.Id,
                            GroupId   = groupid
                        };
                        await _planRepository.InsertSectionGroup(newSectionGroup);
                    }
                }
            }
            else
            {
                var section = new Section()
                {
                    Name = "New Section", PatrolId = patrolId, Color = "#00FF00"
                };
                await _planRepository.InsertSection(section);

                var planSection = new PlanSection()
                {
                    PlanId = newPlan.Id, SectionId = section.Id
                };
                await _planRepository.InsertPlanSection(planSection);

                var level = patrolLevels.FirstOrDefault();
                if (level == null)
                {
                    level = new Level()
                    {
                        Name = "New", PatrolId = patrolId
                    };
                    await _planRepository.InsertLevel(level);
                }

                var sectionLevel = new SectionLevel()
                {
                    SectionId = section.Id, LevelId = level.Id, ColumnIndex = 0
                };
                await _planRepository.InsertSectionLevel(sectionLevel);

                var skill = patrolSkills.FirstOrDefault();
                if (skill == null)
                {
                    skill = new Skill()
                    {
                        Name = "New", PatrolId = patrolId
                    };
                    await _planRepository.InsertSkill(skill);
                }

                var sectionSkill = new SectionSkill()
                {
                    SectionId = section.Id, SkillId = skill.Id, RowIndex = 0
                };
                await _planRepository.InsertSectionSkill(sectionSkill);
            }

            return(newPlan);
        }
Exemple #26
0
        public async Task UpdatePlan(PlanDto dto)
        {
            var plan = await _planRepository.GetPlan(dto.Id);

            plan.Name = dto.Name;
            await _planRepository.UpdatePlan(plan);

            var allLevels = (await _planRepository.GetLevels(dto.PatrolId)).ToList();
            var allSkills = (await _planRepository.GetSkills(dto.PatrolId)).ToList();
            var allGroups = (await _groupRepository.GetGroupsForPatrol(dto.PatrolId)).ToList();

            //update existing sections
            var sections = await _planRepository.GetSectionsForPlan(dto.Id);

            foreach (var section in sections)
            {
                var newSection = dto.Sections.SingleOrDefault(x => x.Id == section.Id);

                if (newSection == null)
                {
                    //remove
                    await _planRepository.DeleteSection(section);
                }
                else
                {
                    section.Name  = newSection.Name;
                    section.Color = newSection.Color;
                    await _planRepository.UpdateSection(section);

                    //sync levels
                    var sectionLevels = (await _planRepository.GetSectionLevels(section.Id)).OrderBy(x => x.ColumnIndex).ToList();
                    foreach (var sectionLevel in sectionLevels)
                    {
                        var newSectionlevel = newSection.Levels.SingleOrDefault(x => x.Id == sectionLevel.Id);
                        if (newSectionlevel == null)
                        {
                            await _planRepository.DeleteSectionLevel(sectionLevel);
                        }
                        else
                        {
                            sectionLevel.ColumnIndex = newSectionlevel.ColumnIndex;
                            sectionLevel.LevelId     = newSectionlevel.Level.Id;
                            await _planRepository.UpdateSectionLevel(sectionLevel);
                        }
                    }

                    foreach (var newSectionLevel in newSection.Levels.Where(x => x.Id == default(int)))
                    {
                        var sectionLevel = new SectionLevel()
                        {
                            SectionId   = section.Id,
                            ColumnIndex = newSectionLevel.ColumnIndex,
                            LevelId     = newSectionLevel.Level.Id
                        };
                        await _planRepository.InsertSectionLevel(sectionLevel);
                    }

                    //sync skills
                    var sectionSkills = (await _planRepository.GetSectionSkills(section.Id)).OrderBy(x => x.RowIndex).ToList();
                    foreach (var sectionSkill in sectionSkills)
                    {
                        var newSectionSkill = newSection.Skills.SingleOrDefault(x => x.Id == sectionSkill.Id);
                        if (newSectionSkill == null)
                        {
                            await _planRepository.DeleteSectionSkill(sectionSkill);
                        }
                        else
                        {
                            sectionSkill.RowIndex = newSectionSkill.RowIndex;
                            sectionSkill.SkillId  = newSectionSkill.Skill.Id;
                            await _planRepository.UpdateSectionSkill(sectionSkill);
                        }
                    }

                    foreach (var newSectionSkill in newSection.Skills.Where(x => x.Id == default(int)))
                    {
                        var sectionSkill = new SectionSkill()
                        {
                            SectionId = section.Id,
                            RowIndex  = newSectionSkill.RowIndex,
                            SkillId   = newSectionSkill.Skill.Id
                        };
                        await _planRepository.InsertSectionSkill(sectionSkill);
                    }

                    //sync groups
                    var sectionGroups = (await _planRepository.GetSectionGroups(section.Id)).ToList();
                    foreach (var sectionGroup in sectionGroups)
                    {
                        var newSectionGroup = newSection.Groups.SingleOrDefault(x => x.Id == sectionGroup.Id);
                        if (newSectionGroup == null)
                        {
                            await _planRepository.DeleteSectionGroup(sectionGroup);
                        }
                        else
                        {
                            sectionGroup.GroupId = newSectionGroup.GroupId;
                            await _planRepository.UpdateSectionGroup(sectionGroup);
                        }
                    }

                    foreach (var newSectionGroup in newSection.Groups.Where(x => x.Id == default(int)))
                    {
                        var sectionGroup = new SectionGroup()
                        {
                            SectionId = section.Id,
                            GroupId   = newSectionGroup.GroupId
                        };
                        await _planRepository.InsertSectionGroup(sectionGroup);
                    }
                }
            }

            //create new sections
            foreach (var newSection in dto.Sections.Where(x => x.Id == default(int)))
            {
                //save new sections
                var section = new Section()
                {
                    Name     = newSection.Name,
                    PatrolId = plan.PatrolId,
                    Color    = newSection.Color
                };
                await _planRepository.InsertSection(section);

                var planSection = new PlanSection()
                {
                    PlanId    = plan.Id,
                    SectionId = section.Id
                };
                await _planRepository.InsertPlanSection(planSection);

                foreach (var newLevel in newSection.Levels)
                {
                    var sectionLevel = new SectionLevel()
                    {
                        SectionId   = section.Id,
                        ColumnIndex = newLevel.ColumnIndex,
                        LevelId     = newLevel.Level.Id
                    };
                    await _planRepository.InsertSectionLevel(sectionLevel);
                }

                foreach (var newSkill in newSection.Skills)
                {
                    var sectionSkill = new SectionSkill()
                    {
                        SectionId = section.Id,
                        RowIndex  = newSkill.RowIndex,
                        SkillId   = newSkill.Skill.Id
                    };
                    await _planRepository.InsertSectionSkill(sectionSkill);
                }
            }
        }
Exemple #27
0
        private static void FillWithSubSections(List <ConfigurationSection> sectionList, SectionGroup group, string groupXPath, Configuration configuration, string location)
        {
            foreach (SectionDefinition section in group.Sections)
            {
                var sect = location == null?configuration.GetSection($"{groupXPath}/{section.Name}") : configuration.GetSection($"{groupXPath}/{section.Name}", location);

                sectionList.Add(sect);
            }

            foreach (SectionGroup subGroup in group.SectionGroups)
            {
                FillWithSubSections(sectionList, subGroup, $"{groupXPath}/{subGroup.Name}", configuration, location);
            }
        }
        public async Task <IActionResult> UploadExcel(IFormFile masterFile)
        {
            if (masterFile == null || masterFile.Length == 0)
            {
                return(Content("File not selected"));
            }

            //check if file extension is excel
            string fileExtension = Path.GetExtension(masterFile.FileName);

            //Validate uploaded file and return error
            if (fileExtension != ".xls" && fileExtension != ".xlsx")
            {
                //ViewBag.Message = "Please select the excel file with .xls or .xlsx extension";
                //return View();
            }

            //Generate full filepath and save file
            var filePath = Path.Combine(Directory.GetCurrentDirectory(), _environment.WebRootPath, "uploads/" + masterFile.FileName);

            using (var bits = new FileStream(filePath, FileMode.Create))
            {
                await masterFile.CopyToAsync(bits);
            }

            FileInfo file = new FileInfo(filePath);

            //Install-Package EPPlus.Core -Version 1.5.4
            using (ExcelPackage package = new ExcelPackage(file))
            {
                ExcelWorksheet workSheet = package.Workbook.Worksheets["Sheet1"];
                int            totalRows = workSheet.Dimension.Rows;

                HashSet <MasterTableLine> masterLines = new HashSet <MasterTableLine>();

                string lineSection      = null;
                string lineSectionGroup = null;
                string modelName        = null;

                for (int i = 1; i <= totalRows; i++)
                {
                    Console.WriteLine("Countering" + i);
                    int next = i + 1;

                    bool sectionBool      = workSheet.Cells[i, 3].Style.Font.Bold;
                    bool sectionGroupBool = workSheet.Cells[next, 3].Style.Font.Bold;
                    if (sectionBool && sectionGroupBool)
                    {
                        modelName        = workSheet.Cells[i - 1, 1].Value != null ? workSheet.Cells[i - 1, 1].Value.ToString() : modelName;
                        lineSection      = workSheet.Cells[i, 3].Value != null ? workSheet.Cells[i, 3].Value.ToString() : "";
                        lineSectionGroup = workSheet.Cells[next, 3].Value != null ? workSheet.Cells[next, 3].Value.ToString() : "";
                    }

                    if (sectionBool && !sectionGroupBool)
                    {
                        lineSectionGroup = workSheet.Cells[i, 3].Value != null ? workSheet.Cells[i, 3].Value.ToString() : "";
                    }

                    bool containsPart = workSheet.Cells[i, 4].Value != null;

                    if (!sectionBool && containsPart)
                    {
                        masterLines.Add(new MasterTableLine
                        {
                            ModelName    = modelName,
                            SerialNumber = workSheet.Cells[i, 6].Value != null ? workSheet.Cells[i, 6].Value.ToString() : "",
                            Section      = lineSection,
                            SectionGroup = lineSectionGroup,
                            PartName     = workSheet.Cells[i, 3].Value != null ? workSheet.Cells[i, 3].Value.ToString() : "",
                            PartNumber   = workSheet.Cells[i, 4].Value != null ? workSheet.Cells[i, 4].Value.ToString() : "",
                            Quantity     = workSheet.Cells[i, 5].Value != null ? workSheet.Cells[i, 5].Value.ToString() : "",
                            Remarks      = workSheet.Cells[i, 7].Value != null ? workSheet.Cells[i, 7].Value.ToString() : "",
                            Brand        = "Komatsu"
                        });
                    }
                }


                file.Delete();
                int count = 0;

                //get data to db
                foreach (var line in masterLines)
                {
                    Console.WriteLine("Cycle" + count++);
                    Console.WriteLine("Started db operation");
                    if (line.Brand != "")
                    {
                        Brand brand = new Brand
                        {
                            Name = line.Brand
                        };

                        Brand dbBrand = _dbContext.Brands.Where(b => b.Name == brand.Name).FirstOrDefault();
                        if (dbBrand == null)
                        {
                            _dbContext.Brands.Add(brand);
                            _dbContext.SaveChanges();
                        }
                        //Install - Package FlexLabs.EntityFrameworkCore.Upsert - Version 2.1.2
                        //_dbContext.Upsert(brand).On(b => new { b.Name }).Run();
                        Console.WriteLine("Added brand");
                        brand = _dbContext.Brands.Where(b => b.Name == line.Brand).FirstOrDefault();

                        if (line.ModelName != "")
                        {
                            Machine machine = new Machine
                            {
                                ModelName    = line.ModelName,
                                SerialNumber = line.SerialNumber,
                                Brand        = brand
                            };

                            Machine dbMachine = _dbContext.Machines.Where(m => m.ModelName == machine.ModelName).FirstOrDefault();

                            if (dbMachine == null)
                            {
                                _dbContext.Machines.Add(machine);
                                _dbContext.SaveChanges();
                            }

                            // _dbContext.Upsert(machine).On(m => new { m.ModelName }).Run();
                            Console.WriteLine("Added machine");
                            machine = _dbContext.Machines.Where(m => m.ModelName == line.ModelName).FirstOrDefault();


                            if (line.Section != "")
                            {
                                Section section = new Section
                                {
                                    SectionName = line.Section
                                };

                                Section dbSection = _dbContext.Sections.Where(s => s.SectionName == section.SectionName).FirstOrDefault();

                                if (dbSection == null)
                                {
                                    _dbContext.Sections.Add(section);
                                    _dbContext.SaveChanges();
                                }

                                //_dbContext.Sections.Upsert(section).On(s => new { s.SectionName }).Run();
                                Console.WriteLine("Added section");
                                section = _dbContext.Sections.Where(s => s.SectionName == line.Section).FirstOrDefault();

                                if (line.SectionGroup != "")
                                {
                                    SectionGroup sectionGroup = new SectionGroup
                                    {
                                        SectionGroupName = line.SectionGroup,
                                        Section          = section
                                    };

                                    SectionGroup dbSectionGroup = _dbContext.SectionGroups
                                                                  .Where(s => s.SectionGroupName == sectionGroup.SectionGroupName)
                                                                  .FirstOrDefault();

                                    if (dbSectionGroup == null)
                                    {
                                        _dbContext.SectionGroups.Add(sectionGroup);
                                        _dbContext.SaveChanges();
                                    }

                                    //_dbContext.SectionGroups.Upsert(sectionGroup).On(s => new { s.SectionGroupName }).Run();
                                    Console.WriteLine("Added sectiongroup");
                                    sectionGroup = _dbContext.SectionGroups.Where(sg => sg.SectionGroupName == sectionGroup.SectionGroupName).FirstOrDefault();

                                    if (line.PartName != "")
                                    {
                                        Category category = new Category
                                        {
                                            CategoryName = line.PartName,
                                        };

                                        Category dbCategory = _dbContext.Categories.Where(c => c.CategoryName == category.CategoryName).FirstOrDefault();

                                        if (dbCategory == null)
                                        {
                                            _dbContext.Categories.Add(category);
                                            _dbContext.SaveChanges();
                                        }

                                        //_dbContext.Categories.Upsert(category).On(s => new { s.CategoryName }).Run();
                                        Console.WriteLine("Added category");
                                        category = _dbContext.Categories.Where(s => s.CategoryName == category.CategoryName).FirstOrDefault();

                                        //brand.Categories.Add(category);


                                        if (line.PartNumber != "")
                                        {
                                            Product product = new Product
                                            {
                                                PartNumber = line.PartNumber,
                                                Brand      = brand,
                                                Category   = category,
                                                Section    = section,
                                                Quantity   = line.Quantity,
                                                Remarks    = line.Remarks
                                            };

                                            Product dbProduct = _dbContext.Products.Where(p => p.PartNumber == product.PartNumber).FirstOrDefault();

                                            if (dbProduct == null)
                                            {
                                                _dbContext.Products.Add(product);
                                                _dbContext.SaveChanges();
                                            }

                                            //_dbContext.Products.Upsert(product).On(s => new { s.PartNumber }).Run();
                                            Console.WriteLine("Added product");
                                            product = _dbContext.Products.Where(p => p.PartNumber == product.PartNumber).FirstOrDefault();

                                            //Brand One to many
                                            brand.Categories.Add(category);

                                            brand.Machines.Add(machine);

                                            brand.Products.Add(product);

                                            brand.SectionGroups.Add(sectionGroup);

                                            brand.Sections.Add(section);

                                            section.SectionGroups.Add(sectionGroup);

                                            category.Products.Add(product);

                                            _dbContext.SaveChanges();

                                            //ProductSectionGroup relationship
                                            ProductSectionGroup productSectionGroup = new ProductSectionGroup
                                            {
                                                Product      = product,
                                                SectionGroup = sectionGroup
                                            };

                                            ProductSectionGroup dbProductSectionGroup = _dbContext
                                                                                        .Set <ProductSectionGroup>()
                                                                                        .Where(psg => psg.SectionGroupId == sectionGroup.SectionGroupId && psg.ProductId == product.ProductId)
                                                                                        .FirstOrDefault();

                                            if (dbProductSectionGroup == null)
                                            {
                                                product.ProductSectionGroups.Add(productSectionGroup);
                                                _dbContext.SaveChanges();
                                            }

                                            //ProductMachine relationship
                                            ProductMachine productMachine = new ProductMachine
                                            {
                                                Product = product,
                                                Machine = machine
                                            };

                                            ProductMachine dbProductMachine = _dbContext
                                                                              .Set <ProductMachine>()
                                                                              .Where(pm => pm.ProductId == product.ProductId && pm.MachineId == machine.MachineId)
                                                                              .FirstOrDefault();

                                            if (dbProductMachine == null)
                                            {
                                                product.ProductMachines.Add(productMachine);
                                                _dbContext.SaveChanges();
                                            }

                                            //MachineSection relationship
                                            MachineSection machineSection = new MachineSection
                                            {
                                                Section = section,
                                                Machine = machine
                                            };

                                            MachineSection dbMachineSection = _dbContext
                                                                              .Set <MachineSection>()
                                                                              .Where(m => m.MachineId == machine.MachineId && m.SectionId == section.SectionId)
                                                                              .FirstOrDefault();

                                            if (dbMachineSection == null)
                                            {
                                                machine.MachineSections.Add(machineSection);
                                                _dbContext.SaveChanges();
                                            }

                                            //MachineSectionGroup relationship
                                            MachineSectionGroup machineSectionGroup = new MachineSectionGroup
                                            {
                                                SectionGroup = sectionGroup,
                                                Machine      = machine
                                            };

                                            MachineSectionGroup dbMachineSectionGroup = _dbContext
                                                                                        .Set <MachineSectionGroup>()
                                                                                        .Where(m => m.MachineId == machine.MachineId && m.SectionGroupId == sectionGroup.SectionGroupId)
                                                                                        .FirstOrDefault();

                                            if (dbMachineSectionGroup == null)
                                            {
                                                machine.MachineSectionGroups.Add(machineSectionGroup);
                                                _dbContext.SaveChanges();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    Console.WriteLine("Ended dbOpration");
                }
                _dbContext.SaveChanges();

                Console.WriteLine("End of request");
                return(Ok());
            }
        }
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter();
     base.InternalProcessRecord();
     if (base.HasErrors)
     {
         return;
     }
     if (File.Exists(base.IISConfigFilePath))
     {
         using (ServerManager serverManager = new ServerManager())
         {
             bool              flag              = false;
             SectionGroup      sectionGroup      = serverManager.GetApplicationHostConfiguration().RootSectionGroup.SectionGroups["system.webServer"];
             SectionDefinition sectionDefinition = sectionGroup.Sections["system.management.wsmanagement.config"];
             if (sectionDefinition != null)
             {
                 base.WriteVerbose(Strings.VerboseRemoveWSManConfigSection(base.IISConfigFilePath));
                 sectionGroup.Sections.Remove("system.management.wsmanagement.config");
                 flag = true;
             }
             ConfigurationElementCollection collection = serverManager.GetApplicationHostConfiguration().GetSection("system.webServer/globalModules").GetCollection();
             for (int i = 0; i < collection.Count; i++)
             {
                 ConfigurationElement configurationElement = collection[i];
                 object attributeValue = configurationElement.GetAttributeValue("name");
                 if (attributeValue != null && string.Equals("WSMan", attributeValue.ToString(), StringComparison.InvariantCultureIgnoreCase))
                 {
                     base.WriteVerbose(Strings.VerboseRemoveWSManGlobalModule("WSMan", base.IISConfigFilePath));
                     collection.Remove(configurationElement);
                     flag = true;
                     break;
                 }
             }
             foreach (Site site in serverManager.Sites)
             {
                 if (site.Id == 1L)
                 {
                     base.DefaultSiteName = site.Name;
                 }
             }
             if (flag)
             {
                 serverManager.CommitChanges();
                 if (base.DefaultSiteName != null)
                 {
                     base.RestartDefaultWebSite();
                 }
             }
         }
     }
     if (File.Exists(base.WSManCfgSchemaFilePath))
     {
         try
         {
             File.Delete(base.WSManCfgSchemaFilePath);
         }
         catch (SystemException ex)
         {
             this.WriteWarning(Strings.ErrorFailedToRemoveWinRMSchemaFile(base.WSManCfgSchemaFilePath, ex.ToString()));
         }
     }
     TaskLogger.LogEnter();
 }
 public bool Save(SectionGroup sectionGroup)
 {
     return(true);
     //TODO Implement
 }
 public bool Delete(SectionGroup element)
 {
     throw new NotImplementedException();
 }
Exemple #32
0
        public async Task <IActionResult> UploadMaster([FromForm] IFormFile masterFile)
        {
            if (masterFile == null || masterFile.Length == 0)
            {
                return(Content("File not selected"));
            }

            //check if file extension is excel
            string fileExtension = Path.GetExtension(masterFile.FileName);

            //Validate uploaded file and return error
            if (fileExtension != ".xls" && fileExtension != ".xlsx")
            {
                ViewBag.Message = "Please select the excel file with .xls or .xlsx extension";
                return(View());
            }

            //Generate full filpath and save file
            var filePath = Path.Combine(Directory.GetCurrentDirectory(), _environment.WebRootPath, masterFile.FileName);

            using (var bits = new FileStream(filePath, FileMode.Create))
            {
                await masterFile.CopyToAsync(bits);
            }

            FileInfo file = new FileInfo(filePath);

            //dotnet add package EPPlus.Core--version 1.5.4
            using (ExcelPackage package = new ExcelPackage(file))
            {
                ExcelWorksheet workSheet = package.Workbook.Worksheets["Sheet1"];
                int            totalRows = workSheet.Dimension.Rows;

                List <MasterTableLine> masterLines = new List <MasterTableLine>();

                string lineSection      = null;
                string lineSectionGroup = null;
                string modelName        = null;

                for (int i = 1; i <= totalRows; i++)
                {
                    Console.WriteLine("Countering" + i);
                    int next = i + 1;



                    bool sectionBool      = workSheet.Cells[i, 3].Style.Font.Bold;
                    bool sectionGroupBool = workSheet.Cells[next, 3].Style.Font.Bold;
                    if (sectionBool && sectionGroupBool)
                    {
                        modelName        = workSheet.Cells[i - 1, 1].Value != null ? workSheet.Cells[i - 1, 1].Value.ToString() : modelName;
                        lineSection      = workSheet.Cells[i, 3].Value != null ? workSheet.Cells[i, 3].Value.ToString() : "";
                        lineSectionGroup = workSheet.Cells[next, 3].Value != null ? workSheet.Cells[next, 3].Value.ToString() : "";
                    }

                    if (sectionBool && !sectionGroupBool)
                    {
                        lineSectionGroup = workSheet.Cells[i, 3].Value != null ? workSheet.Cells[i, 3].Value.ToString() : "";
                    }

                    bool containsPart = workSheet.Cells[i, 4].Value != null;

                    if (!sectionBool && containsPart)
                    {
                        masterLines.Add(new MasterTableLine
                        {
                            ModelName    = modelName,
                            SerialNumber = workSheet.Cells[i, 6].Value != null ? workSheet.Cells[i, 6].Value.ToString() : "",
                            Section      = lineSection,
                            SectionGroup = lineSectionGroup,
                            PartName     = workSheet.Cells[i, 3].Value != null ? workSheet.Cells[i, 3].Value.ToString() : "",
                            PartNumber   = workSheet.Cells[i, 4].Value != null ? workSheet.Cells[i, 4].Value.ToString() : "",
                            Quantity     = workSheet.Cells[i, 5].Value != null ? workSheet.Cells[i, 5].Value.ToString() : "",
                            Remarks      = workSheet.Cells[i, 7].Value != null ? workSheet.Cells[i, 7].Value.ToString() : "",
                            Brand        = "Komatsu"
                        });
                    }
                }



                //get data to db
                foreach (var line in masterLines)
                {
                    if (line.Brand != "")
                    {
                        Brand brand = new Brand
                        {
                            Name = line.Brand
                        };
                        _dbContext.Upsert(brand).On(b => new { b.Name }).Run();
                        brand = _dbContext.Brands.Where(m => m.Name == line.Brand).FirstOrDefault();

                        if (line.ModelName != "")
                        {
                            Machine machine = new Machine
                            {
                                ModelName    = line.ModelName,
                                SerialNumber = line.SerialNumber,
                                BrandId      = brand.BrandId
                            };

                            _dbContext.Upsert(machine).On(m => new { m.ModelName }).Run();
                            machine = _dbContext.Machines.Where(m => m.ModelName == line.ModelName).FirstOrDefault();


                            if (line.Section != "")
                            {
                                Section section = new Section
                                {
                                    SectionName = line.Section
                                };
                                _dbContext.Sections.Upsert(section).On(s => new { s.SectionName }).Run();
                                section = _dbContext.Sections.Where(s => s.SectionName == line.Section).FirstOrDefault();

                                section.Machines.Add(machine);
                                machine.Sections.Add(section);
                                _dbContext.SaveChanges();


                                if (line.SectionGroup != "")
                                {
                                    SectionGroup sectionGroup = new SectionGroup
                                    {
                                        SectionGroupName = line.SectionGroup,
                                        SectionId        = section.SectionId
                                    };

                                    _dbContext.SectionGroups.Upsert(sectionGroup).On(s => new { s.SectionGroupName }).Run();
                                    sectionGroup = _dbContext.SectionGroups.Where(s => s.SectionGroupName == line.SectionGroup).FirstOrDefault();

                                    sectionGroup.Machines.Add(machine);
                                    machine.SectionGroups.Add(sectionGroup);
                                    _dbContext.SaveChanges();

                                    if (line.PartName != "")
                                    {
                                        Category category = new Category
                                        {
                                            CategoryName = line.PartName,
                                        };

                                        _dbContext.Categories.Upsert(category).On(s => new { s.CategoryName }).Run();
                                        category = _dbContext.Categories.Where(s => s.CategoryName == line.PartName).FirstOrDefault();

                                        brand.Categories.Add(category);
                                        _dbContext.SaveChanges();

                                        if (line.PartNumber != null)
                                        {
                                            Product product = new Product
                                            {
                                                PartNumber = line.PartNumber,
                                                BrandId    = brand.BrandId,
                                                CategoryId = category.CategoryId,
                                                Quantity   = line.Quantity,
                                                Remarks    = line.Remarks
                                            };

                                            _dbContext.Products.Upsert(product).On(s => new { s.PartNumber }).Run();
                                            product = _dbContext.Products.Where(s => s.PartNumber == line.PartNumber).FirstOrDefault();

                                            brand.Products.Add(product);
                                            section.Products.Add(product);
                                            sectionGroup.Products.Add(product);
                                            category.Products.Add(product);
                                            _dbContext.SaveChanges();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }


                return(View(nameof(UploadMaster), masterLines));

                //List<Machine> machineList = new List<Machine>();

                //for (int i = 2; i <= totalRows; i++)
                //{
                //    machineList.Add(new Machine
                //    {
                //        //BrandId = Convert.ToInt32(workSheet.Cells[i, 1].Value.ToString()),
                //        ModelName = workSheet.Cells[i, 2].Value.ToString(),
                //        Description = workSheet.Cells[i, 3].Value.ToString(),
                //        BrandId = Convert.ToInt32(workSheet.Cells[i, 4].Value.ToString())
                //    });
                //}

                //foreach (var machine in machineList)
                //{
                //    //dotnet add package FlexLabs.EntityFrameworkCore.Upsert--version 2.1.2
                //    _dbContext.Upsert(machine).On(b => new { b.ModelName }).Run();
                //}
            }
        }