public void AddPerson(PersonViewModel personViewModel) { UN_Persons per = new UN_Persons(); per.Name = personViewModel.Name; per.Address = personViewModel.Address; per.EGN = personViewModel.EGN; per.GSM = personViewModel.GSM; this._databaseContext.UN_Persons.Add(per); this.Save(); }
private void btnImportPersonsAndPositions_Click(object sender, RoutedEventArgs e) { OpenFileDialog opf = new OpenFileDialog(); if (opf.ShowDialog().Value == true) { Excel.Worksheet xlsheet; Excel.Workbook xlwkbook; xlwkbook = (Excel.Workbook)System.Runtime.InteropServices.Marshal.BindToMoniker(opf.FileName); xlsheet = (Excel.Worksheet)xlwkbook.ActiveSheet; Excel.Range oRng; int id_currentDepartment = 0; int id_parentDepartment = 0; for (int i = 1; i < 12; i++) { using (var logic = new NomenclaturesLogic()) { string gstr; if (id_currentDepartment == 0) { gstr = this.GetRangeValue(i, 1, xlsheet); if (gstr == "") { continue; } if (gstr == "1000") { gstr = this.GetRangeValue(i, 2, xlsheet); id_currentDepartment = logic.GetDepartmentByName(gstr).id_department; id_parentDepartment = id_currentDepartment; continue; } else if(gstr == "999") { gstr = this.GetRangeValue(i, 2, xlsheet); id_currentDepartment = logic.GetDepartmentShiftByName(gstr, id_currentDepartment).id_department; continue; } } else { gstr = this.GetRangeValue(i, 1, xlsheet); if (gstr == "") { continue; } #region parse department if (gstr == "1000") { gstr = this.GetRangeValue(i, 2, xlsheet); id_currentDepartment = logic.GetDepartmentByName(gstr).id_department; id_parentDepartment = id_currentDepartment; continue; } else if (gstr == "999") { gstr = this.GetRangeValue(i, 2, xlsheet); id_currentDepartment = logic.GetDepartmentShiftByName(gstr, id_parentDepartment).id_department; continue; } #endregion else { gstr = this.GetRangeValue(i, 2, xlsheet); HR_StructurePositions spos = null; UN_Persons per = new UN_Persons(); HR_Contracts con = new HR_Contracts(); HR_Assignments ass = new HR_Assignments(); spos = logic.FindStructurePositionByName(gstr, id_currentDepartment); if(spos == null) { spos = new HR_StructurePositions(); spos.id_globalPosition = logic.GetGlobalPositionByName(gstr).id_globalPosition; spos.id_department = id_currentDepartment; spos.IsActive = true; spos.ActiveFrom = DateTime.Now; spos.StaffCount = 1; logic.HR_StructurePositions.Add(spos); } gstr = this.GetRangeValue(i, 3, xlsheet); per.Name = gstr; con.UN_Persons = per; ass.HR_StructurePositions = spos; ass.AdditionalHolidays = 0; ass.NumberHolidays = 20; ass.HR_Contracts = con; ass.IsActive = true; ass.IsAdditionalAssignment = false; logic.UN_Persons.Add(per); logic.HR_Contracts.Add(con); logic.HR_Assignments.Add(ass); logic.Save(); spos.Order = spos.id_structurePosition; logic.Save(); } } } } } }