Exemple #1
0
 public static Location UpdateModel(this Location location, LocationEditModel locationEditModel)
 {
     if (locationEditModel != null)
     {
         var locationInfo = string.Concat(locationEditModel.Address1?.Trim(), locationEditModel.Address2?.Trim(), locationEditModel.City?.Trim(), locationEditModel.State?.Trim(), locationEditModel.PostalCode?.Trim(), locationEditModel.Name?.Trim(), locationEditModel.PhoneNumber?.Trim());
         if (string.IsNullOrWhiteSpace(locationInfo))
         {
             location = null;
         }
         else
         {
             if (location == null || locationEditModel.Id.GetValueOrDefault() != 0)
             {
                 location = new Location();
             }
             location.Address1    = locationEditModel.Address1;
             location.Address2    = locationEditModel.Address2;
             location.City        = locationEditModel.City;
             location.Country     = locationEditModel.Country;
             location.Name        = locationEditModel.Name;
             location.PhoneNumber = locationEditModel.PhoneNumber;
             if (!string.IsNullOrWhiteSpace(locationEditModel.PostalCode))
             {
                 location.PostalCode = new PostalCodeGeo {
                     PostalCode = locationEditModel.PostalCode, City = locationEditModel.City, State = locationEditModel.State
                 };
             }
             location.State = locationEditModel.State;
             return(location);
         }
     }
     return(location);
 }
 public static Location UpdateModel(this Location location, LocationEditModel locationEditModel)
 {
     if (locationEditModel != null)
     {
         var locationInfo = string.Concat(locationEditModel.Address1?.Trim(), locationEditModel.Address2?.Trim(), locationEditModel.City?.Trim(), locationEditModel.State?.Trim(), locationEditModel.PostalCode?.Trim(), locationEditModel.Name?.Trim(), locationEditModel.PhoneNumber?.Trim());
         if (string.IsNullOrWhiteSpace(locationInfo))
         {
             location = null;
         }
         else
         {
             if (location == null || locationEditModel.Id.GetValueOrDefault() != 0)
             {
                 location = new Location();
             }
             location.Address1 = locationEditModel.Address1;
             location.Address2 = locationEditModel.Address2;
             location.City = locationEditModel.City;
             location.Country = locationEditModel.Country;
             location.Name = locationEditModel.Name;
             location.PhoneNumber = locationEditModel.PhoneNumber;
             if (!string.IsNullOrWhiteSpace(locationEditModel.PostalCode))
             {
                 location.PostalCode = new PostalCodeGeo { PostalCode = locationEditModel.PostalCode, City = locationEditModel.City, State = locationEditModel.State };
             }
             location.State = locationEditModel.State;
             return location;
         }
     }
     return location;
 }
        public async Task ReportErrorsWhenPostalCodeInvalid()
        {
            // arrage
            var mediator = new Mock<IMediator>();
            var validator = new LocationEditModelValidator(mediator.Object);
            var model = new LocationEditModel()
            {
                PostalCode = "12345",
                State = "WA",
                City = "Seattle"
            };

            // act
            var errors = await validator.Validate(model);

            // assert
            Assert.True(errors.ContainsKey("PostalCode"));
        }