public ProductViewModel(Product product) { Id = product.Id; Name = product.Name; if (product.Category != null) { CategoryId = product.Category.Id; } }
public ActionResult Create(ProductViewModel model) { var product = new Product(); var category = Session.Get<Category>(model.CategoryId); model.UpdateEntity(product, HttpContext.User.Identity.Name, category); Session.Save(product); return RedirectToAction("Index"); }
internal void UpdateEntity(Product product, string userName, Category category) { product.Name = Name; product.UserName = userName; product.Category = category; }