public static void Main(string[] args) { BinaryFormatter serializer = new BinaryFormatter(); if (args.Length > 0) { Department dept = new Department(); dept.Title = args[0]; dept.AddEmployee(3, 34000); dept.AddEmployee(5, 56000); dept.AddEmployee(2, 23000); dept.AddEmployee(4, 45000); dept.AddEmployee(6, 67000); using (var target = new FileStream("dept.dat", FileMode.Create)) serializer.Serialize(target, dept); } else { Department dept; using (var mapping = MemoryMappedFile.CreateFromFile("dept.dat")) { using (var source = mapping.CreateViewStream()) dept = (Department)serializer.Deserialize(source); } Console.WriteLine("Employees of {0} department", dept.Title); foreach (Employee emp in dept.Employees) { Console.WriteLine(emp); } } }
public ActionResult Index() { List <Department> all = new List <Department>(); Department accounting = new Department("Бухгалтерия", "Челябинск, Бр. Кашириных, 129, кабинет 82", "8-800-555-35-35"); Department management = new Department("Менеджеры", "Челябинск, Бр. Кашириных, 129, кабинет 181", "8-800-555-55-00"); Department programmers = new Department("Программисты", "Челябинск, Бр. Кашириных, 129, кабинет 327", "8-800-545-28-10"); Department programmersASP = new Department("ASP-программисты", "Челябинск, Бр.Кашириных, 129, кабинет 329", "8-800-555-55-00"); Employee accountant = new Employee("Пупкина", "Лариса", "Ивановна", 39, "8-982-872-17-27"); Employee accountant2 = new Employee("Пирожкова", "Евгения", "Лаврентьевна", 48, "8-351-922-00-97"); Employee manager = new Employee("Управленцева", "Александра", "Васильевна", 29, "8-902-720-12-12"); Employee programmerASP = new Employee("Сименкова", "Дарья", "Игоревна", 20, "8-900-072-27-27"); Employee programmerASP2 = new Employee("Огородникова", "Валерия", "Дмитриевна", 20, "8-964-298-29-99"); accounting.AddEmployee(accountant); accounting.AddEmployee(accountant2); management.AddEmployee(manager); programmersASP.AddEmployee(programmerASP); programmersASP.AddEmployee(programmerASP2); programmers.AddDepartment(programmersASP); all.Add(accounting); all.Add(management); all.Add(programmers); return(View(all)); //return View(); }
public static void Main(string[] args) { XmlSerializer serializer = new XmlSerializer(typeof(Department)); if (args.Length > 0) { Department dept = new Department(); dept.Title = args[0]; dept.AddEmployee(3, 32000); dept.AddEmployee(5, 54000); dept.AddEmployee(6, 65000); dept.AddEmployee(4, 43000); dept.AddEmployee(2, 21000); using (Stream output = File.Create("dept.xml")) serializer.Serialize(output, dept); } else { Department dept; using (Stream input = File.OpenRead("dept.xml")) dept = (Department)serializer.Deserialize(input); Console.WriteLine($"Employees of {dept.Title} department"); foreach (Employee emp in dept.Employees) { Console.WriteLine(emp); } } }
public Employee AddEmployee(Department dept, Employee emp) { dept.AddEmployee(emp); context.SaveChanges(); return(emp); }
public static void Main() { int num = int.Parse(Console.ReadLine()); Employee currentEmployee; List <Department> departments = new List <Department>(); for (int i = 0; i < num; i++) { string[] args = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string dept = args[3]; double salary = double.Parse(args[1]); currentEmployee = new Employee ( args[0], salary, args[2], dept ); if (args.Length == 5) { currentEmployee.AddEmail(args[4]); } else if (args.Length == 6) { currentEmployee.AddEmail(args[4]); currentEmployee.AddAge(int.Parse(args[5])); } if (departments.Any(x => x.Name == dept)) { var deptAndEmployees = departments .FirstOrDefault(x => x.Name == dept); deptAndEmployees?.AddEmployee(currentEmployee); } else { var currentDept = new Department(dept); currentDept.AddEmployee(currentEmployee); departments.Add(currentDept); } } StringBuilder sb = new StringBuilder(); Department highestAverageDept = departments.OrderByDescending(x => x.AverageSalary).ThenBy(y => y.Name).FirstOrDefault(); sb.AppendLine($"Highest Average Salary: {highestAverageDept.Name}"); foreach (var employee in highestAverageDept.Employees.OrderByDescending(x => x.Salary).ThenBy(y => y.Name)) { sb.AppendLine($"{employee.Name} {employee.Salary:0.00} {employee.Email} {employee.Age}"); } Console.WriteLine(sb.ToString().Trim()); }
static void Main() { var departments = new List <Department>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var args = Console.ReadLine().Split(); Employee employee = FillEmployeeInfo(args); string departmentName = args[3]; var department = departments.FirstOrDefault(d => d.Name == departmentName); if (department == null) { var newDep = new Department(departmentName); newDep.AddEmployee(employee); departments.Add(newDep); } else { department.AddEmployee(employee); } } PrintResult(departments); }
static void Main(string[] args) { List <Department> departments = new List <Department>(); int peopleCount = int.Parse(Console.ReadLine()); for (int person = 0; person < peopleCount; person++) { string[] personInformation = Console.ReadLine().Split(); string departmentName = personInformation[3]; if (!departments.Any(d => d.Name == departmentName)) { Department dep = new Department(departmentName); departments.Add(dep); } Department department = departments.FirstOrDefault(d => d.Name == departmentName); Employee employee = ParseEmployee(personInformation); department.AddEmployee(employee); } Department highestAverageDepartment = departments.OrderByDescending(d => d.AverageSalary).First(); Console.WriteLine($"Highest Average Salary: {highestAverageDepartment.Name}"); foreach (var employee in highestAverageDepartment.Employees.OrderByDescending(e => e.Salary)) { Console.WriteLine($"{employee.Name} {employee.Salary:f2} {employee.Email} {employee.Age}"); } }
public ActionResult AddDepartment(int EmployeeId, int departmentId) { Employee foundEmployee = Employee.Find(EmployeeId); Department foundDepartment = Department.Find(departmentId); foundDepartment.AddEmployee(foundEmployee); return(RedirectToAction("Details", new { departmentId = foundDepartment.id })); }
public ActionResult Create(int departmentEmployeeId, string departmentName) { Department newDepartment = new Department(departmentName); newDepartment.Save(); Employee foundEmployee = Employee.Find(departmentEmployeeId); newDepartment.AddEmployee(foundEmployee); return(RedirectToAction("Index")); }
public static void Main(string[] args) { var serializer = new System.Xml.Serialization.XmlSerializer(typeof(Department)); if (args.Length > 0) { Department dept = new Department { Title = args[0] }; dept.AddEmployee(4, 43000); dept.AddEmployee(6, 65000); dept.AddEmployee(7, 67000); dept.AddEmployee(5, 45000); dept.AddEmployee(3, 23000); dept.AddEmployee(2, 13000); var target = new FileStream("dept.xml", FileMode.Create); serializer.Serialize(target, dept); target.Close(); } else { var source = new FileStream("dept.xml", FileMode.Open); Department dept = (Department)serializer.Deserialize(source); source.Close(); Console.WriteLine($"Employees of {dept.Title} department"); foreach (var emp in dept.Employees) { Console.WriteLine(emp); } } }
public static void Main(string[] args) { var serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); if (args.Length > 0) { Department dept = new Department { Title = args[0] }; dept.AddEmployee(4, 45000); dept.AddEmployee(5, 53000); dept.AddEmployee(6, 67000); dept.AddEmployee(2, 23000); dept.AddEmployee(3, 32000); dept.AddEmployee(7, 76000); var doc = new FileStream("dept.dat", FileMode.Create); serializer.Serialize(doc, dept); doc.Close(); } else { var doc = new FileStream("dept.dat", FileMode.Open); Department dept = (Department)serializer.Deserialize(doc); doc.Close(); Console.WriteLine($"Employees of {dept.Title} department"); foreach (Employee emp in dept.Employees) { Console.WriteLine(emp); } } }
public static void Main() { Department depart = new Department(); depart.AddEmployee(new Permanent("KIM", 1000)); depart.AddEmployee(new Permanent("LEE", 1500)); depart.AddEmployee(new Permanent("JUN", 2000)); depart.AddEmployee(new PartTime("PARK", 10, 200)); depart.AddEmployee(new PartTime("HONG", 20, 170)); depart.AddEmployee(new Temporal("YANG", 100, 0.3)); depart.ShowEmployee(); }
public void GetValueTest() { var employee = new Employee() { Name = "Jason", Gender = Gender.Male, Salary = 10000.01m, HomeAddress = new Address { CountryId = 123, City = "ShenZhen", Detail = "****", }, }; Assert.Equal("Jason", Converter.GetValue(employee, "Name")); Assert.Equal("ShenZhen", Converter.GetValue(employee, "HomeAddress.City")); Converter.SetValue(employee, "Name", "Lucky"); Assert.Equal("Lucky", Converter.GetValue(employee, "Name")); Converter.SetValue(employee, "HomeAddress.City", "XinHua"); Assert.Equal("XinHua", Converter.GetValue(employee, "HomeAddress.City")); var department = new Department("Develop"); department.AddEmployee(employee); var empX = department[0]; Assert.NotNull(empX); var empY = department["Lucky"]; Assert.NotNull(empY); empX = (Employee)Converter.GetValue(department, "[0]"); Assert.NotNull(empX); empY = (Employee)Converter.GetValue(department, "['Lucky']"); Assert.NotNull(empX); }
public void GetValueTest() { var emp1 = new Employee() { Name = "Popeye Zhong", Gender = Gender.Male, Salary = 10000.01m, HomeAddress = new Address { CountryId = 123, City = "Wuhan", Detail = "****", }, }; Assert.Equal("Popeye Zhong", Zongsoft.Common.Convert.GetValue(emp1, "Name")); Assert.Equal("Wuhan", Zongsoft.Common.Convert.GetValue(emp1, "HomeAddress.City")); Zongsoft.Common.Convert.SetValue(emp1, "Name", "Popeye"); Assert.Equal("Popeye", Zongsoft.Common.Convert.GetValue(emp1, "Name")); Zongsoft.Common.Convert.SetValue(emp1, "HomeAddress.City", "Shenzhen"); Assert.Equal("Shenzhen", Zongsoft.Common.Convert.GetValue(emp1, "HomeAddress.City")); var department = new Department("Develop"); department.AddEmployee(emp1); var empX = department[0]; Assert.NotNull(empX); var empY = department["Popeye"]; Assert.NotNull(empY); empX = (Employee)Zongsoft.Common.Convert.GetValue(department, "[0]"); Assert.NotNull(empX); empY = (Employee)Zongsoft.Common.Convert.GetValue(department, "['Popeye']"); Assert.NotNull(empX); }
static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List <Department> departments = new List <Department>(); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine() .Split(' ') .ToArray(); string name = input[0]; decimal salary = decimal.Parse(input[1]); string position = input[2]; string department = input[3]; Employee emp = new Employee() { Name = name, Position = position, Department = department, Salary = salary, Email = "n/a", Age = -1 }; if (input.Length == 6) { string email = input[4]; int age = int.Parse(input[5]); emp.Email = email; emp.Age = age; } else if (input.Length == 5) { if (input[4].Length > 5) { string email = input[4]; emp.Email = email; } else { int age = int.Parse(input[4]); emp.Age = age; } } if (departments.Any(d => d.Name == department)) { Department currentDep = departments .SingleOrDefault(d => d.Name == department); if (!currentDep.employees.Any(e => e.Name == name && e.Salary == salary && e.Position == position)) { currentDep.AddEmployee(emp); } } else { Department dept = new Department(); dept.Name = department; dept.AddEmployee(emp); departments.Add(dept); } } Department depWithHishestSalary = departments .OrderByDescending(d => d.employees.Select(e => e.Salary).Average()) .First(); Console.WriteLine($"Highest Average Salary: {depWithHishestSalary.Name}"); foreach (var e in depWithHishestSalary.employees.OrderByDescending(e => e.Salary)) { Console.WriteLine($"{e.Name} {e.Salary} {e.Email} {e.Age}"); } }