public AccountController(KatieStoreEntities2 entities = null, ControllerContext context = null, IBraintreeGateway braintreeGateway = null) { if (entities == null) { db = new KatieStoreEntities2(); } else { db = entities; } if (context != null) { ControllerContext = context; } if (braintreeGateway == null) { _braintreeGateway = new BraintreeGateway { Environment = Braintree.Environment.SANDBOX, MerchantId = ConfigurationManager.AppSettings["Braintree.MerchantId"], PublicKey = ConfigurationManager.AppSettings["Braintree.PublicKey"], PrivateKey = ConfigurationManager.AppSettings["Braintree.PrivateKey"] };; } else { _braintreeGateway = braintreeGateway; } _currentCustomer = null; }
public static Basket GetBasket(this Controller controller, KatieStoreEntities2 entities) { Basket b = null; if (controller.User.Identity.IsAuthenticated) { b = entities.AspNetUsers.FirstOrDefault(x => x.UserName == controller.User.Identity.Name).Baskets.FirstOrDefault(); } else if (controller.HttpContext.Request.Cookies.AllKeys.Contains("cart")) { int cartId = int.Parse(controller.HttpContext.Request.Cookies["cart"].Value); b = entities.Baskets.Find(cartId); } if (b == null) { b = new Basket(); b.Created = DateTime.UtcNow; b.Modified = DateTime.UtcNow; if (controller.HttpContext.User.Identity.IsAuthenticated) { b.AspNetUserID = entities.AspNetUsers.FirstOrDefault(x => x.UserName == controller.HttpContext.User.Identity.Name).Id; } entities.Baskets.Add(b); entities.SaveChanges(); if (!controller.HttpContext.User.Identity.IsAuthenticated) { controller.HttpContext.Response.Cookies.Add(new HttpCookie("cart", b.ID.ToString())); } } return(b); }
public AccountController() { db = new KatieStoreEntities2(); _braintreeGateway = new BraintreeGateway { Environment = Braintree.Environment.SANDBOX, MerchantId = ConfigurationManager.AppSettings["Braintree.MerchantId"], PublicKey = ConfigurationManager.AppSettings["Braintree.PublicKey"], PrivateKey = ConfigurationManager.AppSettings["Braintree.PrivateKey"] }; }
public ProductController(KatieStoreEntities2 entities = null, ControllerContext context = null) { if (entities == null) { db = new KatieStoreEntities2(); } else { db = entities; } if (context != null) { ControllerContext = context; } }
public ProductController() { db = new KatieStoreEntities2(); }