protected override void Context()
        {
            Username = "******";

            base.Context();

            CustomerService.Stub(
                x => x.UpdateCustomer(Arg<string>.Is.Equal(Username), Arg<UpdateCustomerRequest>.Is.Anything))
                .WhenCalled(x => _requestPassedToCustomerService = x.Arguments[1] as UpdateCustomerRequest);

            _updateCustomerInputModel = Builder<UpdateCustomerInputModel>.CreateNew().Build();
            _expectedRequest = new UpdateCustomerRequest
                                   {
                                       Id = _updateCustomerInputModel.CustomerId,
                                       Name = _updateCustomerInputModel.Name,
                                   };

            _expectedRequest.AddContact(new Contact
                                            {
                                                Id = _updateCustomerInputModel.ContactId,
                                                FirstName = _updateCustomerInputModel.ContactFirstName,
                                                LastName = _updateCustomerInputModel.ContactLastName,
                                                Phone = _updateCustomerInputModel.ContactPhone,
                                            });

            _expectedRequest.MailingAddress = new Address
                                                  {
                                                      Id = _updateCustomerInputModel.CustomerId,
                                                      Street = _updateCustomerInputModel.Street,
                                                      AdditionalInfo = _updateCustomerInputModel.AdditionalInfo,
                                                      City = _updateCustomerInputModel.City,
                                                      State = _updateCustomerInputModel.State,
                                                      Zipcode = _updateCustomerInputModel.Zipcode,
                                                  };
        }
        protected override void Context()
        {
            base.Context();

            _updateCustomerRequest = Builder<UpdateCustomerRequest>.CreateNew().Build();

            AuthorizationService.Stub(
                x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<Type>.Is.Equal(typeof (UpdateCustomerRequest)))).
                Return(false);
        }
        protected override void Context()
        {
            base.Context();

            _updateCustomerRequest = Builder<UpdateCustomerRequest>.CreateNew().Build();

            AuthorizationService.Stub(
                x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<Type>.Is.Equal(typeof (UpdateCustomerRequest)))).
                Return(true);

            _updateCustomerRequestValidator = MockRepository.GenerateStub<UpdateCustomerRequestValidator>();
            _updateCustomerRequestValidator.Stub(
                x => x.Validate(Arg<UpdateCustomerRequest>.Is.Equal(_updateCustomerRequest)))
                .Return(new ValidationResult());

            //MockValidatorFactory.Stub(
            //    x => x.Create<UpdateCustomerRequest>())
            //    .Return(_updateCustomerRequestValidator);

            CustomerRepository.Stub(
                x => x.Update(Arg<UpdateCustomerRequest>.Is.Equal(_updateCustomerRequest)))
                .WhenCalled(x => _updateCustomerRequestPassedToRepository = x.Arguments[0] as UpdateCustomerRequest);
        }
        protected override void Context()
        {
            base.Context();

            _updateCustomerRequest = Builder<UpdateCustomerRequest>.CreateNew().Build();

            AuthorizationService.Stub(
                x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<Type>.Is.Equal(typeof (UpdateCustomerRequest)))).
                Return(true);

            _updateCustomerRequestValidator = MockRepository.GenerateStub<UpdateCustomerRequestValidator>();
            _updateCustomerRequestValidator.Stub(
                x => x.Validate(Arg<UpdateCustomerRequest>.Is.Equal(_updateCustomerRequest)))
                .Return(new ValidationResult(new List<ValidationFailure>
                                                 {
                                                     new ValidationFailure("some property",
                                                                           ErrorReturnedFromValidationEngine),
                                                 }));

            //MockValidatorFactory.Stub(
            //    x => x.Create<UpdateCustomerRequest>())
            //    .Return(_updateCustomerRequestValidator);
        }
        private void UpdateCustomer(string username, UpdateCustomerRequest updateCustomerRequest)
        {
            if (!_authorizationService.CanExecute(username, "EditCustomers"))
                throw new SecurityException("User is not authorized to Edit Customers.");

            _customerRepository.Update(updateCustomerRequest);
        }
        public void Update(UpdateCustomerRequest updateCustomerRequest)
        {
            using (var context = new PRToolsEntities())
            {
                IQueryable<Customer> customerEntities =
                    context.Customers.Where(x => x.CustomerId == updateCustomerRequest.Id);
                if (customerEntities.Count() < 1)
                    throw new ObjectNotFoundException();

                Customer customerEntity = customerEntities.FirstOrDefault();
                customerEntity.Name = updateCustomerRequest.Name;
                customerEntity.Phone = updateCustomerRequest.Phone;
                customerEntity.GooglePlacesURL = updateCustomerRequest.GooglePlacesUrl;
                customerEntity.TwitterHandle = updateCustomerRequest.TwitterHandle;
                customerEntity.WebsiteURL = updateCustomerRequest.WebsiteUrl;
                customerEntity.FacebookURL = updateCustomerRequest.FacebookUrl;
                customerEntity.ZFirstName = updateCustomerRequest.ZFirstName;
                customerEntity.ZLastName = updateCustomerRequest.ZLastName;

                if (updateCustomerRequest.ParentCustomerId > 0)
                    customerEntity.ParentCustomerId = updateCustomerRequest.ParentCustomerId;
                else
                {
                    customerEntity.ParentCustomerId = null;
                }

                if(updateCustomerRequest.AccountManagerId > 0)
                    customerEntity.AccountManagerId = updateCustomerRequest.AccountManagerId;
                else
                {
                    customerEntity.AccountManagerId = null;
                }

                if (updateCustomerRequest.CustomerType != Domain.CustomerType.Undefined)
                {
                    string customerTypeKey = updateCustomerRequest.CustomerType.ToString();
                    CustomerType customerType =
                        context.CustomerTypes.FirstOrDefault(x => x.CustomerTypeKey == customerTypeKey);
                    customerEntity.CustomerType = customerType;
                }

                Address addressEntity = context.Addresses.FirstOrDefault();
                addressEntity.Street = updateCustomerRequest.MailingAddress.Street;
                addressEntity.AdditionalInfo = updateCustomerRequest.MailingAddress.AdditionalInfo;
                addressEntity.City = updateCustomerRequest.MailingAddress.City;
                addressEntity.State = updateCustomerRequest.MailingAddress.State;
                addressEntity.Zipcode = updateCustomerRequest.MailingAddress.Zipcode;

                foreach (Domain.Contact contact in updateCustomerRequest.Contacts)
                {
                    int id = contact.Id;
                    Contact contactEntity = context.Contacts.FirstOrDefault(x => x.ContactId == id);

                    contactEntity.FirstName = contact.FirstName;
                    contactEntity.LastName = contact.LastName;
                    contactEntity.Phone = contact.Phone;
                    contactEntity.Email = contact.Email;
                }

                context.SaveChanges();
            }
        }