public async Task <IActionResult> Edit(Address address)
        {
            if (ModelState.IsValid)
            {
                Address oldAddress = addressRepository.GetById(address.AddressId);
                if (oldAddress.Equals(address) && oldAddress.Name == address.Name)
                {
                    return(RedirectToAction("Index"));
                }

                if (oldAddress.Equals(address) && oldAddress.Name != address.Name)
                {
                    oldAddress.Name = address.Name;
                    if (!addressRepository.EditName(oldAddress))
                    {
                        return(BadRequest("could not edit the name"));
                    }
                }

                if (!oldAddress.Equals(address))
                {
                    if (!await addressRepository.Edit(address))
                    {
                        return(BadRequest("could not edit the address"));
                    }
                }


                return(RedirectToAction("Index"));
            }

            return(View(address));
        }            //////////////
예제 #2
0
        public ActionResult EditEmployee(PersonAddressViewModel personAddressViewModel)
        {
            if (ModelState.IsValid)
            {
                var Person  = new Person();
                var Address = new Address();

                Person.FirstName  = personAddressViewModel.FirstName;
                Person.LastName   = personAddressViewModel.LastName;
                Person.Email      = personAddressViewModel.Email;
                Address.Address1  = personAddressViewModel.Address1;
                Address.Address2  = personAddressViewModel.Address2;
                Address.City      = personAddressViewModel.City;
                Address.State     = personAddressViewModel.State;
                Address.ZipCode   = personAddressViewModel.ZipCode;
                Address.AddressId = personAddressViewModel.PersonId;

                _addressRepository.Edit(Address);
                _addressRepository.Save();
                return(RedirectToAction("EmployeeDetails"));
            }
            else
            {
                return(View("EditEmployee", personAddressViewModel));
            }
        }
        public async Task <ActionResult> Edit(int id, Address address)
        {
            try
            {
                Address oldAddress = addressRepository.GetById(id);
                if (oldAddress == null)
                {
                    return(NotFound());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                address.AddressId = oldAddress.AddressId;

                if (oldAddress.Equals(address) && oldAddress.Name == address.Name)
                {
                    return(Ok());
                }

                if (oldAddress.Equals(address) && oldAddress.Name != address.Name)
                {
                    oldAddress.Name = address.Name;
                    if (!addressRepository.EditName(oldAddress))
                    {
                        return(BadRequest("could not edit the name"));
                    }
                }

                if (!oldAddress.Equals(address))
                {
                    if (!await addressRepository.Edit(address))
                    {
                        return(BadRequest("could not edit the address"));
                    }
                }

                return(Ok());
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #4
0
        public bool Edit(Address address, string accountId)
        {
            var userAddress = _userRepository.GetUserAddressById(address.ID,
                                                                 accountId);

            if (userAddress == null)
            {
                return(false);
            }

            userAddress.City       = address.City;
            userAddress.Name       = address.Name;
            userAddress.PostalCode = address.PostalCode;
            userAddress.Street     = address.Street;

            _addressRepository.Edit(userAddress);
            _addressRepository.Save();

            return(true);
        }
 public async Task <bool> Edit(Address address) => await _addressRepository.Edit(address);