public IActionResult Edit(int?Id) { Services.Data.Core.Domain.Product product; if (Id == null) { product = new Services.Data.Core.Domain.Product(); } else { product = _unitOfWork.Products.Get((int)Id); if (product == null) { return(Redirect( "/../Product")); } _unitOfWork.Baskets.Get(product); } var model = new Models.Product(product); // Model parents and children //model.PopulateChilden(); return(View(model)); }
public IActionResult Index() { #if DEBUG // You may want to create a UAT (user exceptance tester) role and check for this: // "if(_unitOfWork.IsUATTester(GetUserId())" // Company SANDBOX Client Id. To go live replace this with the live ID. //ViewBag.ClientId = "{SANDBOX Client Id}"; // Get from a data store or stettings ViewBag.ClientId = PayPal.PayPalClient.SandboxClientId; // Get from a data store or stettings if (PayPal.PayPalClient.SandboxClientId == "{PayPal SANDBOX Client Id}" && PayPal.PayPalClient.SandboxClientSecret == "{PayPal SANDBOX Client Secret}") { ViewBag.ShowErrorMessage = true; } else { ViewBag.ShowErrorMessage = false; } #else // Company LIVE Client Id. To go live replace this with the live ID. ViewBag.ClientId = PayPal.PayPalClient.LiveClientId; // Get from a data store or stettings if (PayPal.PayPalClient.LiveClientId == "{PayPal LIVE Client Id}" && PayPal.PayPalClient.LiveClientSecret == "{PayPal LIVE Client Secret}") { ViewBag.ShowErrorMessage = true; } else { ViewBag.ShowErrorMessage = false; } #endif if (PayPal.PayPalClient.SandboxClientId == "{PayPal SANDBOX Client Id}") { ViewBag.CurrencyCode = "GBP"; // Get from a data store } ViewBag.CurrencySign = "£"; // Get from a data store Models.Basket model = null; if (_unitOfWork.Baskets.GetAll().Count() == 0) { var basket = new Services.Data.Core.Domain.Basket() { Id = 0, CurrencyCode = "GBP", CurrencySymbol = "£", Discount = 0, }; _unitOfWork.Baskets.Add(basket); var product = new Services.Data.Core.Domain.Product() { Id = 0, Name = "Sargon Object Database", Description = "A app for managing information about archaeological objects.", Price = 40, Quantity = 1, Basket = basket, }; _unitOfWork.Products.Add(product); basket.Products.Add(product); product = new Services.Data.Core.Domain.Product() { Id = 1, Name = "Delaney's Photo Renamer", Description = "Photo Renamer automatically prefixes photos with date taken.", Price = 7, Quantity = 1, Basket = basket, }; _unitOfWork.Products.Add(product); basket.Products.Add(product); _unitOfWork.Complete(); model = new Models.Basket(basket); } else { var basket = _unitOfWork.Baskets.GetAll().FirstOrDefault(); model = new Models.Basket(basket); } return(View(model)); }