//
        // GET: /Company/Create
        public ActionResult Create()
        {
            var companyViewModelDD = new CompanyViewModelDD();

            CompanyService.PopulateSelectLists(companyViewModelDD);

            return(View(companyViewModelDD));
        }
 public void PopulateCompanyViewModelDD(CompanyViewModelDD companyViewModelDD, Company company)
 {
     companyViewModelDD.ID                = company.ID;
     companyViewModelDD.CompanyTypeID     = company.CompanyTypeID;
     companyViewModelDD.CompanyCostTypeID = company.CompanyCostTypeID;
     //
     companyViewModelDD.Name             = company.Name;
     companyViewModelDD.RegistrationDate = company.RegistrationDate;
 }
        //
        // GET: /Company/Edit/5
        public ActionResult Edit(int id)
        {
            CompanyViewModelDD companyViewModelDD = new CompanyViewModelDD();
            Company            company            = CompanyService.FindByID(id);

            CompanyService.PopulateCompanyViewModelDD(companyViewModelDD, company);
            CompanyService.PopulateSelectLists(companyViewModelDD);

            return(View(companyViewModelDD));
        }
        public ActionResult Edit(CompanyViewModelDD companyViewModelDD)
        {
            if (ModelState.IsValid)
            {
                Company company = new Company();
                CompanyService.PopulateCompany(companyViewModelDD, company);
                CompanyService.Update(company);

                return(RedirectToAction("Index"));
            }
            CompanyService.PopulateSelectLists(companyViewModelDD);
            return(View(companyViewModelDD));
        }
        public ActionResult Create(CompanyViewModelDD companyViewModelDD)
        {
            if (ModelState.IsValid)
            {
                var company = new Company();
                CompanyService.PopulateCompany(companyViewModelDD, company);
                company.RegistrationDate = DateTime.Now;
                CompanyService.Add(company);

                return(RedirectToAction("Index"));
            }
            CompanyService.PopulateSelectLists(companyViewModelDD);
            return(View(companyViewModelDD));
        }
        public void PopulateSelectLists(CompanyViewModelDD companyViewModelDD)
        {
            var CompanyTypeSelectList = CompanyTypeService.GetAll().Select(companyType => new SelectListItem
            {
                Text     = companyType.CompanyTypeName,
                Value    = companyType.ID.ToString(),
                Selected = companyType.ID == companyViewModelDD.CompanyCostTypeID
            });

            var CompanyCostTypeSelectList = CompanyCostTypeService.GetAll().Select(companyCostType => new SelectListItem
            {
                Text     = companyCostType.CostType,
                Value    = companyCostType.ID.ToString(),
                Selected = companyCostType.ID == companyViewModelDD.CompanyCostTypeID
            });

            companyViewModelDD.CompanyTypes     = CompanyTypeSelectList;
            companyViewModelDD.CompanyCostTypes = CompanyCostTypeSelectList;
        }