Я уже довольно давно создаю новое приложение ASP.NET MVC 5, и теперь, когда я нахожусь на последнем этапе сборки моего приложения, что-то для меня очень очевидно.У меня есть несколько почтовых вызовов в моих контроллерах, и после каждого, после проверки, я следую архитектуре PRG, которая затем позволяет мне передавать некоторые параметры в URL для запроса GET, который затем перестраивает мою ViewModel с информацией, которую яизвлеченные из поста, а также любая информация, сохраненная в базе данных, информация, скрываемая в строителях и т. д., и мне было любопытно, действительно ли это нужно делать?
Моя ViewModel довольно сложна, используетсписки моделей для заполнения раскрывающихся списков в моем представлении, и у меня также есть другие модели в качестве переменных в моей viewmodel, которые я затем заполняю для использования в своем приложении соответствующим образом.
Конечно, у меня есть около 5 DropDownLists в одном из моихГлавные виды, и каждый раз, когда я делаю сообщение, я должен следовать PRG и затем вызывать слой репозитория, чтобы снова заполнить все выпадающие списки, даже если они каждый раз представляют одну и ту же информацию.Я просто думаю, что должен быть лучший способ, но, возможно, я ошибаюсь.
Примеры кода:
public ViewResult RgaByRgaNumber(string strRgaNumber)
{
var vm = new ReturnGoodsAuthorizationViewModel()
{
RGA = _returnGoodsAuthorizationRepository.GetSpecificByRGANumber(strRgaNumber),
RGAItems = _returnGoodsAuthorizationItemRepository.GetByRgaNumber(strRgaNumber),
ReturnGoodsAuthorizations = _returnGoodsAuthorizationRepository.GetAll(),
ReasonCodes = _reasonCodeRepository.GetAll(),
RestockFeeOptions = _restockFeeOptionRepository.GetAll(),
Customers = _customerRepository.GetAll(),
IsUserAllowedToClickOpenCloseRGAButton = _returnGoodsAuthorizationRepository.GetUserAllowedToClickOpenCloseRGAButtonStatus(User.Identity.NameWithoutDomain())
};
vm.SubmitButtonText = vm.GetSubmitButtonText();
vm.RGAClosedOpenStatusText = vm.GetRgaClosedOpenStatusText();
vm.Customer = vm.Customers.First(x => x.CustomerId == vm.RGA.CustomerNumber);
vm.Items = _itemRepository.GetAll(vm.RGA.CustomerNumber);
return View("Index", vm);
}
public ViewResult Index()
{
var vm = new ReturnGoodsAuthorizationViewModel()
{
ReturnGoodsAuthorizations = _returnGoodsAuthorizationRepository.GetAll(),
ReasonCodes = _reasonCodeRepository.GetAll(),
RestockFeeOptions = _restockFeeOptionRepository.GetAll(),
Customers = _customerRepository.GetAll(),
RGA = new ReturnGoodsAuthorization()
{
PreparedByUser = User.Identity.NameWithoutDomain().ToUpper(),
AuthorizedByUser = User.Identity.NameWithoutDomain().ToUpper(),
CreateUser = User.Identity.NameWithoutDomain().ToUpper()
}
};
return View("Index", vm);
}
public ViewResult GetCustomerItemList(string strCustomerNumber)
{
var vm = new ReturnGoodsAuthorizationViewModel()
{
ReturnGoodsAuthorizations = _returnGoodsAuthorizationRepository.GetAll(),
ReasonCodes = _reasonCodeRepository.GetAll(),
RestockFeeOptions = _restockFeeOptionRepository.GetAll(),
Customers = _customerRepository.GetAll(),
RGA = new ReturnGoodsAuthorization()
{
PreparedByUser = User.Identity.NameWithoutDomain().ToUpper(),
AuthorizedByUser = User.Identity.NameWithoutDomain().ToUpper(),
CreateUser = User.Identity.NameWithoutDomain().ToUpper()
}
};
vm.RGA.CustomerNumber = strCustomerNumber;
vm.Customer = vm.Customers.First(x => x.CustomerId == strCustomerNumber);
vm.Items = _itemRepository.GetAll(strCustomerNumber);
Session["ReturnGoodsAuthorizationViewModel"] = vm;
return View("Index", vm);
}
public ViewResult GetItemPrice(string strCustomerNumber, string strItemNumber)
{
if (Session != null && Session["ReturnGoodsAuthorizationViewModel"] != null)
{
var vm = (ReturnGoodsAuthorizationViewModel)Session["ReturnGoodsAuthorizationViewModel"];
vm.ReturnGoodsAuthorizations = _returnGoodsAuthorizationRepository.GetAll();
vm.ReasonCodes = _reasonCodeRepository.GetAll();
vm.RestockFeeOptions = _restockFeeOptionRepository.GetAll();
vm.Customers = _customerRepository.GetAll();
vm.RGA.CustomerNumber = strCustomerNumber;
vm.Items = _itemRepository.GetAll(strCustomerNumber);
vm.Item = vm.Items.First(m => m.Number == strItemNumber);
vm.SubmitButtonText = vm.GetSubmitButtonText();
vm.RGAClosedOpenStatusText = vm.GetRgaClosedOpenStatusText();
vm.IsUserAllowedToClickOpenCloseRGAButton = _returnGoodsAuthorizationRepository.GetUserAllowedToClickOpenCloseRGAButtonStatus(User.Identity.NameWithoutDomain());
Session["ReturnGoodsAuthorizationViewModel"] = vm;
return View("Index", vm);
}
else
{
var vm = new ReturnGoodsAuthorizationViewModel()
{
ReturnGoodsAuthorizations = _returnGoodsAuthorizationRepository.GetAll(),
ReasonCodes = _reasonCodeRepository.GetAll(),
RestockFeeOptions = _restockFeeOptionRepository.GetAll(),
Customers = _customerRepository.GetAll(),
RGA = new ReturnGoodsAuthorization()
{
PreparedByUser = User.Identity.NameWithoutDomain().ToUpper(),
AuthorizedByUser = User.Identity.NameWithoutDomain().ToUpper(),
CreateUser = User.Identity.NameWithoutDomain().ToUpper()
}
};
vm.IsUserAllowedToClickOpenCloseRGAButton = _returnGoodsAuthorizationRepository.GetUserAllowedToClickOpenCloseRGAButtonStatus(User.Identity.NameWithoutDomain().ToUpper());
vm.RGA.CustomerNumber = strCustomerNumber;
vm.Item = _itemRepository.GetItem(strCustomerNumber, strItemNumber);
vm.Items = _itemRepository.GetAll(strCustomerNumber);
Session["ReturnGoodsAuthorizationViewModel"] = vm;
return View("Index", vm);
}
}