Exemplo n.º 1
0
        public ActionResult Create()
        {
            var vm = new CareCompanyCreateVM();
            List <SelectListItem> collectiveAgreements = new List <SelectListItem>();

            collectiveAgreements = new ApplicationDbContext().CollectiveAgreementHeaders.ToList().ConvertAll(c => new SelectListItem
            {
                Value = $"{c.Id}",
                Text  = c.Name
            });
            vm.CollectiveAgreements = new SelectList(collectiveAgreements, "Value", "Text");
            return(View(vm));
        }
Exemplo n.º 2
0
        public ActionResult Create(CareCompanyCreateVM model)
        {
            if (db.CareCompanies.Where(c => c.OrganisationNumber == model.OrganisationNumber).Any())
            {
                ModelState.AddModelError("OrganisationNumber", "Det finns redan ett bolag med det organisationsnumret.");
            }

            if (ModelState.IsValid)
            {
                CareCompany company = new CareCompany()
                {
                    IsActive           = true,
                    CompanyPhoneNumber = model.CompanyPhoneNumber,
                    Postcode           = model.Postcode,
                    City = model.City,
                    OrganisationNumber            = model.OrganisationNumber,
                    StreetAddress                 = model.StreetAddress,
                    SelectedCollectiveAgreementId = model.SelectedCollectiveAgreementId,
                    CollectiveAgreementSpecName   = model.CollectiveAgreementSpecName,
                    AccountNumber                 = model.AccountNumber,
                    CompanyName = model.CompanyName
                };

                db.CareCompanies.Add(company);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            List <SelectListItem> collectiveAgreements = new List <SelectListItem>();

            collectiveAgreements = new ApplicationDbContext().CollectiveAgreementHeaders.ToList().ConvertAll(c => new SelectListItem
            {
                Value = $"{c.Id}",
                Text  = c.Name
            });
            model.CollectiveAgreements = new SelectList(collectiveAgreements, "Value", "Text");
            // If we got this far, something failed, redisplay form
            return(View(model));

            /*
             * ModelState.Remove(nameof(CareCompany.CollectiveAgreementSpecName));
             * if (ModelState.IsValid)
             * {
             *  db.CareCompanies.Add(careCompany);
             *  db.SaveChanges();
             *  return RedirectToAction("Index");
             * }
             *
             * return View(careCompany);
             */
        }