Наследование: PRTools.Domain.Misc.ViewModelBase
Пример #1
0
        public ActionResult ProcessUpdateCustomerInput(UpdateCustomerInputModel updateCustomerInputModel)
        {
            return TryThis(() =>
                               {
                                   try
                                   {
                                       UpdateCustomerRequest request =
                                           _mappingEngine.Map<UpdateCustomerInputModel, UpdateCustomerRequest>(updateCustomerInputModel);
                                       request.AddContact(
                                           _mappingEngine.Map<UpdateCustomerInputModel, Contact>(updateCustomerInputModel));

                                       UpdateCustomer(User.Identity.Name, request);

                                       TempData["Message"] = "Customer has been updated successfully";

                                       return RedirectToAction("CustomerManagement", "Customer");
                                   }
                                   catch (ValidationException validationException)
                                   {
                                       var viewModel =
                                           new UpdateCustomerViewModel(new List<string> {validationException.Message});
                                       return View("UpdateCustomer", viewModel);
                                   }
                               });
        }
        protected override void Context()
        {
            Username = "******";

            base.Context();

            _customerReturnedFromService = Builder<Domain.Customer>.CreateNew().Build();
            _customerReturnedFromService.MailingAddress = Builder<Address>.CreateNew().Build();
            _customerReturnedFromService.AddContact(Builder<Contact>.CreateNew().Build());

            // load customers
            for (int i = 0; i < 10; i++) { _lcs.Add(Builder<Domain.Customer>.CreateNew().Build()); }

            CustomerService.Stub(x => x.GetCustomer(Arg<string>.Is.Equal(Username),Arg<int>.Is.Equal(CustomerId)))
                .Return(_customerReturnedFromService);

            CustomerService.Stub(x => x.GetCustomers(Arg<string>.Is.Equal(Username), Arg<GetCustomersRequest>.Is.Anything))
                .Return(_lcs);

            _expectedViewModel = new UpdateCustomerViewModel
                                     {
                                         Name = _customerReturnedFromService.Name,
                                         Street = _customerReturnedFromService.MailingAddress.Street,
                                         AdditionalInfo = _customerReturnedFromService.MailingAddress.AdditionalInfo,
                                         City = _customerReturnedFromService.MailingAddress.City,
                                         State = _customerReturnedFromService.MailingAddress.State,
                                         Zipcode = _customerReturnedFromService.MailingAddress.Zipcode,
                                         ContactFirstName = _customerReturnedFromService.Contacts.First().FirstName,
                                         ContactLastName = _customerReturnedFromService.Contacts.First().LastName,
                                         ContactPhone = _customerReturnedFromService.Contacts.First().Phone,
                                         CustomerId = _customerReturnedFromService.CustomerId,
                                         Phone = _customerReturnedFromService.Phone,
                                         MailingAddressId = _customerReturnedFromService.MailingAddress.Id,
                                         ContactId = _customerReturnedFromService.Contacts.First().Id,
                                         ContactEmail = _customerReturnedFromService.Contacts.First().Email,
                                         GooglePlacesUrl = _customerReturnedFromService.GooglePlacesUrl,
                                         TwitterHandle = _customerReturnedFromService.TwitterHandle,
                                         WebsiteUrl = _customerReturnedFromService.WebsiteUrl,
                                         CustomerType = _customerReturnedFromService.CustomerType.ToString(),
                                         ParentCustomerId = _customerReturnedFromService.ParentCustomerId,
                                         ListName = _customerReturnedFromService.ListName,
                                         FacebookUrl = _customerReturnedFromService.FacebookUrl
                                     };
            _lcs.ForEach(x => _expectedViewModel.AddParentCustomer(new CustomerViewModel
                                                                                   {
                                                                                       Id = x.CustomerId,
                                                                                       Name = x.Name,
                                                                                   }));
        }