Esempio n. 1
0
        public ActionResult Save(StaffAddress staffAddress)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new StaffAddressViewModel
                {
                    StaffAddress = staffAddress,
                    AddressTypes = _context.AddressTypes.ToList()
                };
                return(View("StaffAddressForm", viewModel));
            }
            if (staffAddress.Id == 0)
            {
                _context.StaffAddresses.Add(staffAddress);
            }

            else
            {
                var staffAddressInDb = _context.CustomerAddress.Single(m => m.Id == staffAddress.Id);
                staffAddressInDb.AddressTypeId = staffAddress.AddressTypeId;
                staffAddressInDb.StreetAddress = staffAddress.StreetAddress;
                staffAddressInDb.Address2      = staffAddress.Address2;
                staffAddressInDb.City          = staffAddress.City;
                staffAddressInDb.State         = staffAddress.State;
                staffAddressInDb.ZipCode       = staffAddress.ZipCode;
            }
            _context.SaveChanges();
            return(RedirectToAction("Details", "Staff", new { id = staffAddress.StaffId }));
        }
Esempio n. 2
0
        public ActionResult StaffAddressForm(int staffId)
        {
            var viewModel = new StaffAddressViewModel
            {
                StaffAddress = new StaffAddress()
                {
                    StaffId = staffId,
                },
                AddressTypes = _context.AddressTypes.ToList()
            };

            return(View("StaffAddressForm", viewModel));
        }
Esempio n. 3
0
        public ActionResult Delete(int id)
        {
            var staffAddress = _context.StaffAddresses.Include(x => x.AddressType).SingleOrDefault(m => m.Id == id);

            if (staffAddress == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new StaffAddressViewModel
            {
                StaffAddressId = id,
                StaffAddress   = staffAddress,
            };

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

            if (staffAddress == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new StaffAddressViewModel
            {
                StaffAddress = staffAddress,
                AddressTypes = _context.AddressTypes.ToList()
            };

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