Esempio n. 1
0
        public IActionResult UpdateDealershipAddress(DealershipAddressFormViewModel dealershipAddressFormViewModel)
        {
            try
            {
                dealershipAddressFormViewModel.Heading         = "Edit Dealership Address";
                dealershipAddressFormViewModel.SaveButtonText  = "Update";
                dealershipAddressFormViewModel.States          = GetStates();
                dealershipAddressFormViewModel.DealershipsEdit = GetDealershipsWithDefaultSelect();

                if (!ModelState.IsValid)
                {
                    dealershipAddressFormViewModel.Dealerships         = GetDealershipsWithAddresses();
                    dealershipAddressFormViewModel.DealershipAddresses = GetDealershipAddressesByDealershipId(dealershipAddressFormViewModel.DealershipId);

                    return(View("DealershipAddressForm", dealershipAddressFormViewModel));
                }

                var dealershipAddress = _businessLogics.DealershipAddressBusinessLogic.GetSingle(
                    da => da,
                    da => da.DealershipAddressId == dealershipAddressFormViewModel.DealershipAddressId);

                if (dealershipAddress == null)
                {
                    return(BadRequest("Dealership address does not exist"));
                }

                _businessLogics.DealershipAddressBusinessLogic.Update(dealershipAddress, new DealershipAddressDto
                {
                    DealershipId = dealershipAddressFormViewModel.DealershipIdNew,
                    Street       = dealershipAddressFormViewModel.Street,
                    City         = dealershipAddressFormViewModel.City,
                    StateId      = dealershipAddressFormViewModel.StateId,
                    ZipCode      = dealershipAddressFormViewModel.ZipCode,
                    IsActive     = dealershipAddressFormViewModel.IsActive
                });

                _businessLogics.Save();

                dealershipAddressFormViewModel.SuccessMessage = "Dealership address successfully updated";

                ModelState.Remove(nameof(dealershipAddressFormViewModel.DealershipId));

                dealershipAddressFormViewModel.DealershipId        = dealershipAddressFormViewModel.DealershipIdNew;
                dealershipAddressFormViewModel.Dealerships         = GetDealershipsWithAddresses();
                dealershipAddressFormViewModel.DealershipAddresses = GetDealershipAddressesByDealershipId(dealershipAddressFormViewModel.DealershipIdNew);
            }
            catch (Exception ex)
            {
                dealershipAddressFormViewModel.ErrorMessage        = "An error has occurred";
                dealershipAddressFormViewModel.Dealerships         = GetDealershipsWithAddresses();
                dealershipAddressFormViewModel.DealershipAddresses = GetDealershipAddressesByDealershipId(dealershipAddressFormViewModel.DealershipId);
            }

            return(View("DealershipAddressForm", dealershipAddressFormViewModel));
        }
Esempio n. 2
0
        public IActionResult CreateDealershipAddress()
        {
            DealershipAddressFormViewModel dealershipAddressFormViewModel = new DealershipAddressFormViewModel
            {
                Dealerships    = GetDealershipsWithDefaultSelect(),
                States         = GetStates(),
                Heading        = "Add Dealership Address",
                SaveButtonText = "Create"
            };

            return(View("DealershipAddressForm", dealershipAddressFormViewModel));
        }
Esempio n. 3
0
        public IActionResult CreateDealershipAddress(DealershipAddressFormViewModel dealershipAddressFormViewModel)
        {
            try
            {
                dealershipAddressFormViewModel.Dealerships = GetDealershipsWithDefaultSelect();
                dealershipAddressFormViewModel.States      = GetStates();

                if (!ModelState.IsValid)
                {
                    return(View("DealershipAddressForm", dealershipAddressFormViewModel));
                }

                _businessLogics.DealershipAddressBusinessLogic.Add(new DealershipAddressDto
                {
                    DealershipId = dealershipAddressFormViewModel.DealershipId,
                    Street       = dealershipAddressFormViewModel.Street,
                    City         = dealershipAddressFormViewModel.City,
                    StateId      = dealershipAddressFormViewModel.StateId,
                    ZipCode      = dealershipAddressFormViewModel.ZipCode
                });

                _businessLogics.Save();

                dealershipAddressFormViewModel.SuccessMessage = "Dealership address successfully added";
                dealershipAddressFormViewModel.DealershipId   = 0;
                dealershipAddressFormViewModel.Street         = string.Empty;
                dealershipAddressFormViewModel.City           = string.Empty;
                dealershipAddressFormViewModel.StateId        = 0;
                dealershipAddressFormViewModel.ZipCode        = string.Empty;

                ModelState.Clear();

                return(View("DealershipAddressForm", dealershipAddressFormViewModel));
            }
            catch (Exception ex)
            {
                dealershipAddressFormViewModel.ErrorMessage = "An error has occurred";
            }

            return(View("DealershipAddressForm", dealershipAddressFormViewModel));
        }