public ActionResult Add(ProductsAddViewModel viewModel) { // ValidateProduct(viewModel.Product); if (ModelState.IsValid) { var product = viewModel.Product; var inventory = viewModel.Inventory; _inventoriesRepository.Add(inventory); var inventoryId = _inventoriesRepository.GetLast(includeRelatedEntoties: true).Id; product.InventoryId = inventoryId; _productsRepository.Add(product); TempData["Message"] = "Votre produit a été ajouté a la liste."; return(RedirectToAction("Index")); } viewModel.Init(_productTypesRepository, _suppliersRepository, _unitsRepository, User.Identity.GetUserId()); return(View(viewModel)); }
public ActionResult Add() { var viewModel = new ProductsAddViewModel(); viewModel.Product.UserId = User.Identity.GetUserId(); //viewModel.Product.User.UserName = User.Identity.GetUserName(); viewModel.Inventory.UserId = User.Identity.GetUserId(); // viewModel.Inventory.User.UserName = User.Identity.GetUserName(); viewModel.Init(_productTypesRepository, _suppliersRepository, _unitsRepository, User.Identity.GetUserId()); return(View(viewModel)); }