public IActionResult Edit(Models.Product model) { if (model != null) { // Temporary remove many to many selected collections, // as they will cause invalid model state if there are any required fields on the many to many selected. ModelState.Clear(); TryValidateModel(model); } if (ModelState.IsValid) { try { _unitOfWork.Products.Add(model.GetCore()); if (_unitOfWork.Complete() == Services.Data.DataStoreResult.Success) { return(Redirect( "/../Product")); } return(View(model)); } catch { ModelState.AddModelError( "Error", "Cannot edit product."); return(View(model)); } } else { _unitOfWork.Baskets.Get(model.GetCore()); model.Backet = new Models.Basket(model.GetCore().Basket); return(View(model)); } }