Esempio n. 1
0
        // GET CREATE CLIENT
        public ViewResult Create()
        {
            var genders = _clientsRepository.Genders.ToList();
            var maritalStatuses = _clientsRepository.MaritalStatuses.ToList();
            var livingEnvironmentTypes = _clientsRepository.LivingEnvironmentTypes.ToList();

            // create view model
            var viewModel = new ClientFormViewModel
            {
                Genders = new SelectList(genders, "GenderID", "GenderName"),
                MaritalStatuses = new SelectList(maritalStatuses, "MaritalStatusID", "MaritalStatusName"),
                LivingEnvironmentTypes = new SelectList(livingEnvironmentTypes, "LivingEnvironmentTypeID", "LivingEnvironmentTypeName")
            };

            return View("Edit", viewModel);
        }
Esempio n. 2
0
        public ActionResult Edit(ClientFormViewModel clientForm)
        {
            var client = Mapper.Map<ClientFormViewModel, Client>(clientForm);

            if (ModelState.IsValid)
            {
                // set the client's user
                client.User_id = _clientsRepository.GetUser(_currentUser.getUserName()).UserID;

                _clientsRepository.SaveClient(client);
                TempData["message"] = "Client: " + client.FirstName + " " + client.LastName + " has been saved.";
                return RedirectToAction("Detail", "Clients", new { client.ClientID });
            }

            //if model state isn't valid
            clientForm.Genders = new SelectList(_clientsRepository.Genders.ToList(), "GenderID", "GenderName", clientForm.GenderID);
            clientForm.MaritalStatuses = new SelectList(_clientsRepository.MaritalStatuses.ToList(), "MaritalStatusID", "MaritalStatusName", clientForm.GenderID);
            clientForm.LivingEnvironmentTypes = new SelectList(_clientsRepository.LivingEnvironmentTypes.ToList(), "LivingEnvironmentTypeID", "LivingEnvironmentTypeName", clientForm.LivingEnvironmentTypeID);
            return View("Edit", clientForm);
        }