コード例 #1
0
 public PartialViewResult CreateContractor()
 {
     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 ContractorModel(items);
     return PartialView(pers);
 }
コード例 #2
0
        public ActionResult CreateContractor(ContractorModel 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 contractor = ContractorFactory.CreateContractor(newcontractor.Firstname, newcontractor.Lastname,
                    newcontractor.BirthDate,
                    skill, address, company, newcontractor.WorkExp, salary);
                PersonRepository.AddPerson(contractor);

                var pers = PersonRepository.GetAllFirstAndLastNames();
                return PartialView("WorkerList", pers);
            }
            return PartialView(newcontractor);
        }
コード例 #3
0
        public PartialViewResult EditContractor(long id)
        {
            var person = PersonRepository.GetItemById<Contractor>(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 contractor = new ContractorModel(person);
            contractor.Companies = items;

            return PartialView(contractor);
        }
コード例 #4
0
        public ActionResult EditContractor(long id, ContractorModel editedContractor)
        {
            if (ModelState.IsValid)
            {
                var newContractor = new ContractorDetailsDto();
                editedContractor.ConvertToDto(newContractor);
                var currentContractor = PersonRepository.GetItemById<Contractor>(id);
                var currentAddress = AddressRepository.GetItemById<Address>(currentContractor.Address.Id);
                AddressRepository.UpdateAddress(currentAddress, editedContractor.City, editedContractor.Street);
                var newCompany = CompanyRepository.GetItemById<Company>(newContractor.CompanyId);
                var currentsalary = PersonRepository.GetItemById<Salary>(currentContractor.Salary.Id);
                PersonRepository.UpdateContractor(currentContractor, newContractor, newCompany, currentsalary);

                var pers = PersonRepository.GetAllFirstAndLastNames();
                return PartialView("WorkerList", pers);
            }
            return PartialView(editedContractor);
        }
コード例 #5
0
 public PartialViewResult DetailsContractor(long id)
 {
     var person = PersonRepository.GetItemById<Contractor>(id);
     var contractor = new ContractorModel(person);
     return PartialView(contractor);
 }