Esempio n. 1
0
        public ActionResult Save(CustomerPhoneNumber customerPhoneNumber)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new CustomerPhoneNumberFormViewModel
                {
                    CustomerPhoneNumber = customerPhoneNumber,
                    PhoneNumberTypes    = _context.PhoneNumberTypes.ToList()
                };
                return(View("CustomerPhoneNumberForm", viewModel));
            }
            if (customerPhoneNumber.Id == 0)
            {
                _context.CustomerPhoneNumbers.Add(customerPhoneNumber);
            }

            else
            {
                var customerPhoneNumberInDb = _context.CustomerPhoneNumbers.Single(m => m.Id == customerPhoneNumber.Id);
                customerPhoneNumberInDb.PhoneNumberTypeId = customerPhoneNumber.PhoneNumberTypeId;
                customerPhoneNumberInDb.PhoneNumber       = customerPhoneNumber.PhoneNumber;
                customerPhoneNumberInDb.PhoneExtension    = customerPhoneNumber.PhoneExtension;
            }
            _context.SaveChanges();
            return(RedirectToAction("Details", "Customers", new { id = customerPhoneNumber.CustomerId }));
        }
Esempio n. 2
0
        public ActionResult CustomerPhoneNumberTypeForm(int customerId)
        {
            var viewModel = new CustomerPhoneNumberFormViewModel
            {
                CustomerPhoneNumber = new CustomerPhoneNumber()
                {
                    CustomerId = customerId,
                },
                PhoneNumberTypes = _context.PhoneNumberTypes.ToList()
            };

            return(View("CustomerPhoneNumberTypeForm", viewModel));
        }
Esempio n. 3
0
        public ActionResult Delete(int id)
        {
            var customerPhoneNumber = _context.CustomerPhoneNumbers.Include(x => x.PhoneNumberType).SingleOrDefault(m => m.Id == id);

            if (customerPhoneNumber == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new CustomerPhoneNumberFormViewModel
            {
                CustomerPhoneNumberId = id,
                CustomerPhoneNumber   = customerPhoneNumber,
            };

            return(View(viewModel));
        }
Esempio n. 4
0
        public ActionResult Edit(int id)
        {
            var customerPhoneNumber = _context.CustomerPhoneNumbers.SingleOrDefault(c => c.Id == id);

            if (customerPhoneNumber == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new CustomerPhoneNumberFormViewModel
            {
                CustomerPhoneNumber = customerPhoneNumber,
                PhoneNumberTypes    = _context.PhoneNumberTypes.ToList()
            };

            return(View("CustomerPhoneNumberTypeForm", viewModel));
        }