public ActionResult Add(Models.ShopModel product) { using (var connection = new MySqlConnection(this.connectionString)) { connection.Query <Models.ShopModel>("INSERT INTO products(`name`, `description`, `price`) VALUES(@n, @d, @p)", new { n = product.Name, d = product.Description, p = product.Price }); } return(View()); }
// GET: Shop/Edit/5 public ActionResult Edit(int id) { Models.ShopModel shopModel = shopRepository.GetShopByID(id); var shopViewModel = new ShopEditViewModel(); shopViewModel.Shop = shopModel; var categories = categoryRepository.GetAllCategories(); SelectList categoryList = new SelectList(categories, "CategoryID", "Name"); ViewData["CategoryList"] = categoryList; var address = addressRepository.GetAddressByID(shopModel.AddressID); shopViewModel.Address = address; var allPaymentMethods = paymentMethodsRepository.GetAllPaymentMethods(); ViewData["AllPaymentMethods"] = allPaymentMethods; var shopPaymentMethods = paymentMethodsRepository.GetAllPaymentMethodsByShopId(shopModel.ShopId); List <PaymentMethodViewModel> paymentMethodViewModels = new List <PaymentMethodViewModel>(); foreach (var paymentMethodModel in allPaymentMethods) { var paymentMethodViewModel = new PaymentMethodViewModel(); paymentMethodViewModel.PaymentMethod = paymentMethodModel; foreach (var shopPaymentMethod in shopPaymentMethods) { if (shopPaymentMethod.PaymentMethodID == paymentMethodModel.PaymentMethodID) { paymentMethodViewModel.Selected = true; } } paymentMethodViewModels.Add(paymentMethodViewModel); } shopViewModel.PaymentMethods = paymentMethodViewModels; return(View("EditShop", shopViewModel)); }