public ActionResult Create(Transaction transaction) { if (ModelState.IsValid) { db.Transactions.Add(transaction); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(transaction)); }
public ActionResult Create(Supplier supplier) { if (ModelState.IsValid) { db.Suppliers.Add(supplier); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public ActionResult Create(Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create(Return returns) { if (ModelState.IsValid) { db.Returns.Add(returns); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(returns)); }
public void addToCart(Product product) { var cartItem = context.Carts.SingleOrDefault( c => c.cartId == shoppingCartId && c.productId == product.productId); if (cartItem == null) { cartItem = new Cart { productId = product.productId, cartId = shoppingCartId, count = 1, dateCreated = DateTime.Now }; context.Carts.Add(cartItem); } else { cartItem.count++; } context.SaveChanges(); }
public void addCustomer(Customer customer, string username, UserProfile userProfile) { Customer c = new Customer { firstName = customer.firstName, lastName = customer.lastName, address = customer.address, city = customer.city, state = customer.state, zip = customer.zip, phone = customer.phone, email = customer.email, username = username, profile = userProfile }; context.Customers.Add(c); context.SaveChanges(); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (JBOContext db = new JBOContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
/// <summary> /// Imports the given category from the given CSV stream. /// </summary> /// <param name="type">The type of import.</param> /// <param name="file">The csv file.</param> /// <param name="contentHash">The hash of the csv content.</param> public static Tuple <int, int> FromCSV(ImportCategories type, HttpPostedFileBase csv, string contentHash) { bool error = false; Tuple <int, int> results = null; var profiler = MiniProfiler.Current; using (profiler.Step("Importing From CSV...")) using (var context = new JBOContext()) using (var transactionScope = new TransactionScope()) // Start a transaction so BulkInsert optimization can be used. { switch (type) { case ImportCategories.Sales: results = SalesFromCSV(csv.InputStream, context); break; case ImportCategories.Products: results = ProductsFromCSV(csv.InputStream, context); break; default: error = true; break; } if (error) { // I'm pretty sure C# does this automatically, but just in case // until I can find out for sure... throw new InvalidEnumArgumentException("Invalid import type."); } else { using (profiler.Step("Creating import in context")) { // Something should've been imported. context.Imports.Add( new Import { contentHash = contentHash, type = type, filename = csv.FileName, updatedRecords = results.Item1, newRecords = results.Item2 }); } // All done. Let's save the changes. using (profiler.Step("Save changes")) { context.SaveChanges(); } } // We made it this far. All must be well. transactionScope.Complete(); return(results); } }
public ActionResult AddressAndPayment(FormCollection values) { var order = new Order(); var customer = context.Customers.SingleOrDefault(c => c.username == User.Identity.Name); if (customer != null) { order.orderDate = DateTime.Now; order.customer = customer; try { if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false) { return(View(order)); } else { //order.user.UserName = User.Identity.Name; order.orderDate = DateTime.Now; //save order context.Orders.Add(order); context.SaveChanges(); //process order var cart = ShoppingCart.getCart(this.HttpContext); var products = from i in cart.GetCartItems() select i.productId; foreach (var i in products) { var item = cart.getSale(i); context.Sales.Add(item); context.SaveChanges(); } cart.CreateOrder(order); return(RedirectToAction("Complete", new { id = order.orderId })); } } catch { return(View(order)); } } else { TryUpdateModel(order); try { if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false) { return(View(order)); } else { order.orderDate = DateTime.Now; //save order context.Orders.Add(order); context.SaveChanges(); //process order var cart = ShoppingCart.getCart(this.HttpContext); var products = from i in cart.GetCartItems() select i.productId; foreach (var i in products) { var item = cart.getSale(i); context.Sales.Add(item); context.SaveChanges(); } cart.CreateOrder(order); return(RedirectToAction("Complete", new { id = order.orderId })); } } catch { return(View(order)); } return(View()); } }