private Models.DBObjects.ShopPaymentMethod MapModelToDbObject(ShopPaymentMethodModel shopPaymentMethodModel) { Models.DBObjects.ShopPaymentMethod dbShopPaymentMethod = new Models.DBObjects.ShopPaymentMethod(); if (shopPaymentMethodModel != null) { dbShopPaymentMethod.ShopID = shopPaymentMethodModel.ShopID; dbShopPaymentMethod.PaymentMethodID = shopPaymentMethodModel.PaymentMethodID; return(dbShopPaymentMethod); } return(null); }
private ShopPaymentMethodModel MapDbOjectToModel(Models.DBObjects.ShopPaymentMethod dbShopPaymentMethod) { ShopPaymentMethodModel shopPaymentMethodModel = new ShopPaymentMethodModel(); if (dbShopPaymentMethod != null) { shopPaymentMethodModel.ShopID = dbShopPaymentMethod.ShopID; shopPaymentMethodModel.PaymentMethodID = dbShopPaymentMethod.PaymentMethodID; return(shopPaymentMethodModel); } return(null); }
public ActionResult Edit(int id, FormCollection collection) { try { ShopEditViewModel shopViewModel = new ShopEditViewModel(); TryUpdateModel(shopViewModel); var shopModel = new ShopModel(); shopModel.ShopId = shopViewModel.Shop.ShopId; shopModel.AddressID = shopViewModel.Address.AddressID; shopModel.Email = shopViewModel.Shop.Email; shopModel.Name = shopViewModel.Shop.Name; shopModel.Phone = shopViewModel.Shop.Phone; shopModel.CategoryID = shopViewModel.Shop.CategoryID; shopRepository.UpdateShop(shopModel); var addressModel = new AddressModel(); addressModel.AddressID = shopViewModel.Address.AddressID; addressModel.City = shopViewModel.Address.City; addressModel.Country = shopViewModel.Address.Country; addressModel.County = shopViewModel.Address.County; addressModel.PostCode = shopViewModel.Address.PostCode; addressModel.Street = shopViewModel.Address.Street; addressModel.StreetNumber = shopViewModel.Address.StreetNumber; addressRepository.UpdateAddress(addressModel); shopPaymentMethodsRepository.DeleteShopPaymentMethods(shopViewModel.Shop.ShopId); foreach (var paymentMethodViewModel in shopViewModel.PaymentMethods) { if (paymentMethodViewModel.Selected == true) { var shopPaymentMethod = new ShopPaymentMethodModel(); shopPaymentMethod.PaymentMethodID = paymentMethodViewModel.PaymentMethod.PaymentMethodID; shopPaymentMethod.ShopID = shopViewModel.Shop.ShopId; shopPaymentMethodsRepository.InsertShopPaymentMethod(shopPaymentMethod); } } return(RedirectToAction("Index")); } catch (Exception ex) { HandleErrorInfo error = new HandleErrorInfo(ex, "Shop", "Edit"); return(View("Error", error)); } }
public void InsertShopPaymentMethod(ShopPaymentMethodModel shopPaymentMethodModel) { dbContext.ShopPaymentMethods.InsertOnSubmit(MapModelToDbObject(shopPaymentMethodModel)); dbContext.SubmitChanges(); }