Exemplo n.º 1
0
 public PartialViewResult CreateEmployee()
 {
     var items = new List<SelectListItem>();
     var companies = CompanyRepository.GetAllCompanyNames();
     items.Add(new SelectListItem {Text = "Select copmany", Value = "0", Selected = true});
     foreach (var comp in companies)
     {
         items.Add(new SelectListItem {Text = comp.CompanyNames, Value = comp.Id.ToString()});
     }
     var pers = new EmployeeModel(items);
     return PartialView(pers);
 }
Exemplo n.º 2
0
        public ActionResult CreateEmployee(EmployeeModel newcontractor)
        {
            if (ModelState.IsValid)
            {
                var company = CompanyRepository.GetItemById<Company>(newcontractor.CompanyId);
                var address = new Address(newcontractor.Street, newcontractor.City);
                var skill = new Dictionary<string, int>();
                var salary = new Salary(newcontractor.Salary, 0.0);
                var employee = EmployeeFactory.CreateEmployee(newcontractor.Firstname, newcontractor.Lastname,
                    newcontractor.BirthDate,
                    skill, address, company, newcontractor.WorkExp, salary, newcontractor.Department, newcontractor.Role);
                PersonRepository.AddPerson(employee);

                var pers = PersonRepository.GetAllFirstAndLastNames();
                return PartialView("WorkerList", pers);
            }
            return PartialView(newcontractor);
        }
Exemplo n.º 3
0
 public PartialViewResult EditEmployee(long id)
 {
     var person = PersonRepository.GetItemById<Employee>(id);
     var items = new List<SelectListItem>();
     var companies = CompanyRepository.GetAllCompanyNames();
     //items.Add(new SelectListItem { Text = "No company", Value = "0" });
     foreach (var comp in companies)
     {
         if (comp.CompanyNames == person.Company.CompanyName)
             items.Add(new SelectListItem {Text = comp.CompanyNames, Value = comp.Id.ToString(), Selected = true});
         else
             items.Add(new SelectListItem {Text = comp.CompanyNames, Value = comp.Id.ToString()});
     }
     var emp = new EmployeeModel(person);
     emp.Companies = items;
     return PartialView(emp);
 }
Exemplo n.º 4
0
        public ActionResult EditEmployee(long id, EmployeeModel editedEmployee)
        {
            if (ModelState.IsValid)
            {
                var newEmployee = new EmployeeDetailsDto();
                editedEmployee.ConvertToDto(newEmployee);
                var currentEmployee = PersonRepository.GetItemById<Employee>(id);
                var currentAddress = AddressRepository.GetItemById<Address>(currentEmployee.Address.Id);
                AddressRepository.UpdateAddress(currentAddress, editedEmployee.City, editedEmployee.Street);
                var newCompany = CompanyRepository.GetItemById<Company>(newEmployee.CompanyId);
                var currentsalary = PersonRepository.GetItemById<Salary>(currentEmployee.Salary.Id);
                PersonRepository.UpdateEmployee(currentEmployee, newEmployee, newCompany, currentsalary);

                var pers = PersonRepository.GetAllFirstAndLastNames();
                return PartialView("WorkerList", pers);
            }

            return PartialView(editedEmployee);
        }
Exemplo n.º 5
0
 public PartialViewResult DetailsEmployee(long id)
 {
     var person = PersonRepository.GetItemById<Employee>(id);
     var emp = new EmployeeModel(person);
     return PartialView(emp);
 }