public static Product insertProduct(string name, int stock, int price) { Product p = ProductFactory.insertProduct(name, stock, price); db.Products.Add(p); db.SaveChanges(); return(p); }
public static ProductType insertProductType(string name, string description) { ProductType pt = ProductTypeFactory.insertProductType(name, description); db.ProductTypes.Add(pt); db.SaveChanges(); return(pt); }
public static HeaderTransaction insertHeaderTransaction(int userId, int paymentId, DateTime Date) { HeaderTransaction ht = TransactionFactory.insertHeaderTransaction(userId, paymentId, Date); db.HeaderTransactions.Add(ht); db.SaveChanges(); return(ht); }
public static PaymentType InsertPaymentType(string type) { PaymentType paytype = PaymentTypeFactory.InsertPaymentType(type); db.PaymentTypes.Add(paytype); db.SaveChanges(); return(paytype); }
public static Cart InsertCart(int userId, int productId, int quantity) { Cart c = CartFactory.InsertCart(userId, productId, quantity); db.Carts.Add(c); db.SaveChanges(); return(c); }
public static User InsertUser(string email, string name, string password, string gender, int role) { User u = UserFactory.InsertUser(email, name, password, gender, role); db.Users.Add(u); db.SaveChanges(); return(u); }
public ActionResult Contact([Bind(Include = "Email,Phone,Reason,Message")] ContactForm contactForm) { try { if (ModelState.IsValid) { db.ContactForms.Add(new ContactForm { Email = contactForm.Email, Phone = contactForm.Phone, Reason = contactForm.Reason, Seen = "N", ContactDate = DateTime.Now.ToString(), Message = contactForm.Message }); db.SaveChanges(); return(RedirectToAction("Submitted")); } return(View(contactForm)); } catch (DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } //throw raise; return(RedirectToAction("Error")); } }