コード例 #1
0
        public void Should_DeleteAnEmployee_WhenDeleteingAnEmployee()
        {
            //Arrange
            List <EmployeeModel> employees = new List <EmployeeModel>();

            employees = employeeLogic.GetEmployees().ToList();
            string name = employees[0].Name;

            //Act
            employeeLogic.DeleteEmployee(employees[0].Id);

            //Assert
            Assert.False(employees[0].Name != name);
        }
コード例 #2
0
ファイル: EditEmployeesUI.cs プロジェクト: Lidda/project---p4
 private void DeleteEmployee_Click(object sender, EventArgs e)
 {
     if (selectedEmployee.ID > 0)
     {
         if (MessageBox.Show("Weet u zeker dat u deze medewerker wilt verwijderen?", "Deleten...", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             employeeLogic.DeleteEmployee(selectedEmployee);
             selectedEmployee = new Employee();
             MessageBox.Show("Medewerker is succesvol gedeletet");
             ShowPanel("PNL_ManageEmployees");
         }
     }
     else
     {
         MessageBox.Show("Selecteer eerst een medewerker");
     }
 }
コード例 #3
0
 public ActionResult Delete(int id, Employee employee)
 {
     try
     {
         bool status = empLogic.DeleteEmployee(id, employee);
         if (status)
         {
             TempData["deleteStatus"] = "true";
             return(RedirectToAction("Index"));
         }
         else
         {
             TempData["deleteStatus"] = "false";
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         TempData["deleteStatus"] = "false";
         return(RedirectToAction("Index", "Employee"));
     }
 }
コード例 #4
0
        public void DeleteEmployee_ShouldDeleteRecord_WhenNotExistingIdIsPassed()
        {
            // Arrange
            var context = this.GetDbContext();

            this.PopulateData(context);
            Exception exception = null;
            // Act
            var service     = new EmployeeLogic(context, mapper);
            var oldEmployee = context.Companies.Find(40);

            try
            {
                service.DeleteEmployee(oldEmployee.Id);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // Assert
            Assert.NotNull(exception);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            IAwardLogic    awardLogic    = new AwardLogic();
            IEmployeeLogic employeeLogic = new EmployeeLogic();

            bool isRunning = true;

            while (isRunning)
            {
                Console.WriteLine("1. Employee");
                Console.WriteLine("2. Award");
                Console.WriteLine("3. Exit");
                Console.WriteLine();

                int decision;
                int second_decision;
                if (int.TryParse(Console.ReadLine(), out decision))
                {
                    switch (decision)
                    {
                    case 1:
                        Console.WriteLine("1. Show all");
                        Console.WriteLine("2. Add new employee");
                        Console.WriteLine("3. Delete employee by id");
                        Console.WriteLine("4. Add new award for employee");
                        Console.WriteLine("5. Exit");

                        if (int.TryParse(Console.ReadLine(), out second_decision))
                        {
                            switch (second_decision)
                            {
                            case 1:
                                List <Employee> employees = employeeLogic.SelectEmployee();

                                foreach (var item in employees)
                                {
                                    Console.Write($"ID employee: {item.Id}, ");
                                    Console.Write($"name: {item.Name}, ");
                                    Console.Write($"date of birth: {item.DateOfBirth}, ");
                                    Console.Write($"age: {item.Age}, ");
                                    if (item.Awards.Count > 0)
                                    {
                                        Console.WriteLine("awards:");
                                        foreach (var award in item.Awards)
                                        {
                                            Console.Write($"ID award: {award.Id}, ");
                                            Console.WriteLine($"award title: {award.Title}");
                                        }
                                        Console.WriteLine();
                                    }
                                    else
                                    {
                                        Console.WriteLine();
                                    }
                                }
                                break;

                            case 2:
                                string   name;
                                DateTime dateOfBirth;
                                int      age;

                                Console.Write("Press name: ");
                                name = Console.ReadLine();

                                Console.Write("Press date of birth (DD.MM.YYYY): ");
                                List <int> date = Console.ReadLine().Split('.').
                                                  Select(x => int.Parse(x)).ToList();
                                dateOfBirth = new DateTime(date[2], date[1], date[0]);

                                Console.Write("Press age: ");
                                age = int.Parse(Console.ReadLine());

                                Console.WriteLine(employeeLogic.InsertIntoEmployee(name, dateOfBirth, age));
                                Console.WriteLine();
                                break;

                            case 3:
                                int id;

                                Console.Write("Press id: ");
                                id = int.Parse(Console.ReadLine());

                                Console.WriteLine(employeeLogic.DeleteEmployee(id));
                                Console.WriteLine();
                                break;

                            case 4:
                                int idAward;
                                int idEmployee;

                                Console.Write("Press award id: ");
                                idAward = int.Parse(Console.ReadLine());

                                Console.Write("Press employee id: ");
                                idEmployee = int.Parse(Console.ReadLine());

                                Console.WriteLine(employeeLogic.AddAwardForEmployee(idEmployee, idAward));
                                Console.WriteLine();
                                break;

                            case 5:
                                break;

                            default:
                                Console.WriteLine("Wrong number!");
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("It is not a number!");
                        }
                        break;

                    case 2:
                        Console.WriteLine("1. Show all");
                        Console.WriteLine("2. Add new award");
                        Console.WriteLine("3. Delete award by id");
                        Console.WriteLine("4. Exit");

                        if (int.TryParse(Console.ReadLine(), out second_decision))
                        {
                            switch (second_decision)
                            {
                            case 1:
                                List <Award> awards = awardLogic.SelectAward();

                                foreach (var item in awards)
                                {
                                    Console.Write($"ID: {item.Id}, ");
                                    Console.WriteLine($"Title: {item.Title}");
                                }
                                Console.WriteLine();
                                break;

                            case 2:
                                string title;

                                Console.Write("Press title: ");
                                title = Console.ReadLine();

                                Console.WriteLine(awardLogic.InsertIntoAward(title));
                                Console.WriteLine();
                                break;

                            case 3:
                                int id;

                                Console.Write("Press id: ");
                                id = int.Parse(Console.ReadLine());

                                Console.WriteLine(awardLogic.DeleteAward(id));
                                Console.WriteLine();
                                break;

                            case 4:
                                break;

                            default:
                                Console.WriteLine("Wrong number!");
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("It is not a number!");
                        }
                        break;

                    case 3:
                        isRunning = false;
                        break;

                    default:
                        Console.WriteLine("Wrong number!");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("It is not a number!");
                }
            }
        }
コード例 #6
0
 // DELETE: api/Employee/Delete?EmpId=1234
 public void Delete(int EmpId)
 {
     _employeeLogic.DeleteEmployee(EmpId);
 }