Saving a default address to a brand new customer

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 лет назад
Hello all,
I have a list of company address that the user can pick from on the registration screen.  The issue that I'm running into is actually saving the data.  I get the following message:

---------------------------------------
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

Source Error:


Line 46:             //    this._entities.Attach(entity);
Line 47:
Line 48:             this._context.SaveChanges();
Line 49:         }
Line 50:

----------------------------------------

I'm running nopCommerce 2.1...
Below is the code I added to the CustomerController.cs file.  

          //CHECK FOR Corporate Site Add-on
          if (_localizationService.GetResource("_Positive.SiteAddressEnabled").ToUpper().Trim() == "TRUE")
          {
            string CorpID = Request.Form["CorporateSiteCustomerNumber"];
            foreach (var i in CorporateSite.GetAllCorporateSites())
            {
              if (CorpID == i.CustomerNumber)
              {

                Core.Domain.Common.Address CorpAddress = new Core.Domain.Common.Address();
                
                CorpAddress.Address1 = i.Address1;
                CorpAddress.Address2 = i.Address2;
                CorpAddress.Company = i.Company;
                CorpAddress.City = i.City;
                StateProvince SP = new StateProvince();
                SP.Abbreviation = i.State;
                CorpAddress.CountryId = 1;
                CorpAddress.StateProvince = SP;
                CorpAddress.ZipPostalCode = i.Zip;
                CorpAddress.CreatedOnUtc = DateTime.UtcNow;

                _workContext.CurrentCustomer.AddAddress(CorpAddress);
                _workContext.CurrentCustomer.SetShippingAddress(CorpAddress);
                //save
                _customerService.UpdateCustomer(_workContext.CurrentCustomer);
                                
                break;
              }
            }
          }
          //------------------------------------------------------------------------
Any help would be greatly appreciated!

Thanks
12 лет назад
this may help
http://stackoverflow.com/questions/5400530/validation-failed-for-one-or-more-entities-while-saving-changes-to-sql-server-dat
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.