public ActionResult CreateUpdateAddress(AUCombAddress record) { if (ModelState.IsValid) { AUAddressRecord address = _addressRepo.GetById(record.AUAddressRecord.AUAddressID); var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer(); record.AUAddressRecord.CreatedBy = CurrentCustomer.Username; record.AUAddressRecord.UpdatedBy = CurrentCustomer.Username; record.AUAddressRecord.CreatedOnDT = System.DateTime.UtcNow; record.AUAddressRecord.UpdatedOnDT = System.DateTime.UtcNow; if (address == null) { _addressRepo.Insert(record.AUAddressRecord); SuccessNotification("Address Created Successfully!"); return RedirectToRoute(new { Action = "CreateUpdateAddress", Controller = "AUConsignor", addressId = record.AUAddressRecord.AUAddressID, saleId = record.saleId }); } else { //use latest consignor record to update with most up-do-date data rather than stale record address.Address1 = record.AUAddressRecord.Address1; address.Address2 = record.AUAddressRecord.Address2; address.AddressHtml = record.AUAddressRecord.AddressHtml; address.City = record.AUAddressRecord.City; address.CountryId = record.AUAddressRecord.CountryId; address.StateProvinceId = record.AUAddressRecord.StateProvinceId; address.ZipPostalCode = record.AUAddressRecord.ZipPostalCode; //address.StateProvinceName = record.StateProvinceName; //address.CountryName = record.CountryName; //try this //.ForMember(dest => dest.CountryName, mo => mo.MapFrom(src => src.Country != null ? src.Country.Name : null)) address.UpdatedOnDT = record.AUAddressRecord.UpdatedOnDT; address.UpdatedBy = record.AUAddressRecord.UpdatedBy; //int id = NopContext.Current.User != null ? NopContext.Current.User.CustomerId : 0 //NopContext.Current.User.CustomerId is no more present in version 3.0 //this is how nop converts it back out //consignor.CreatedOnDT = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc); //public virtual DateTime CreatedOnDT { get; set; } //public virtual string CreatedBy { get; set; } //public virtual DateTime UpdatedOnDT { get; set; } //public virtual string UpdatedBy { get; set; } _addressRepo.Update(address); // _cacheManager.Clear(); //took this out because it was killing the session SuccessNotification("Changed Saved!"); //return View("~/Views/AUConsignor/CreateUpdateAddress.cshtml", address); //not hit first time?? //need redirect so can pick up country/state lists again //if (record.saleId == 0) //{ return RedirectToRoute(new { Action = "CreateUpdateAddress", Controller = "AUConsignor", addressId = record.AUAddressRecord.AUAddressID, saleId = record.saleId }); //} //else //{ // return RedirectToRoute(new // { // Action = "CreateUpdateSale", // Controller = "AUConsignor", // saleId = record.saleId // }); //} } } else { return View(); //return View("~/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); //not hit first time? //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); } }
public ActionResult CreateUpdateAddress(int addressId = 0, int saleId = 0) { AUCombAddress address = new AUCombAddress(); address.AUAddressRecord = new AUAddressRecord(); //must instantiate the record within the record if (addressId > 0) { address.AUAddressRecord = _addressRepo.GetById(addressId); } else { //need to do this to make sure model is valid for ADD address.AUAddressRecord.AUAddressID = 0; } if (saleId > 0) { address.saleId = saleId; } else { //need to do this to make sure model is valid for ADD address.saleId = saleId = 0; } //Populate Countries (see CustomerController) address.AUAddressRecord.AvailableCountries.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries(true)) { address.AUAddressRecord.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.Id.ToString(), Selected = c.Id == address.AUAddressRecord.CountryId }); } // //Populate State/Province (see CustomerController). Had to take the ? away from Country ID as this statement complained //that the parameter was invalid var states = _stateProvinceService.GetStateProvincesByCountryId(address.AUAddressRecord.CountryId, false).ToList(); if (states.Count > 0) { address.AUAddressRecord.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Address.SelectState"), Value = "0" }); foreach (var s in states) { address.AUAddressRecord.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == address.AUAddressRecord.StateProvinceId) }); } } else { bool anyCountrySelected = address.AUAddressRecord.AvailableCountries.Any(x => x.Selected); address.AUAddressRecord.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource(anyCountrySelected ? "Admin.Address.OtherNonUS" : "Admin.Address.SelectState"), Value = "0" }); } return View("~/Views/AUConsignor/CreateUpdateAddress.cshtml", address); //worked first time null }