Exemple #1
0
        public IActionResult Create(CustomerEditModel model)
        {
            if (ModelState.IsValid)
            {
                var customer = new Customer();
                model.UpdateEntity(customer);
                _context.Clients.Add(customer);
                _context.SaveChanges();

                model.UpdateDistricts(customer);
                model.UpdateHousingTypes(customer);
                _context.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View("Save", model));
        }
Exemple #2
0
        public IActionResult Edit(CustomerEditModel model)
        {
            if (ModelState.IsValid)
            {
                var customer = _context.Clients
                               .Include(x => x.DistrictToClients)
                               .Include(x => x.TypesHousingToCustomers)
                               .Include(x => x.Phones)
                               .Single(x => x.Id == model.EditId);

                model.UpdateEntity(customer);
                model.UpdateDistricts(customer);
                model.UpdateHousingTypes(customer);
                _context.Update(customer);

                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View("Save", model));
        }