public ActionResult Edit(int id, customer_tbl customer) { try { // TODO: Add update logic here using (DBModels db = new DBModels()) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(customer_tbl customer) { try { // TODO: Add insert logic here using (DBModels db = new DBModels()) { db.customer_tbl.Add(customer); db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id, customer_tbl customer) { try { // TODO: Add delete logic here using (DBModels db = new DBModels()) { customer = db.customer_tbl.Where(x => x.id == id).FirstOrDefault(); db.customer_tbl.Remove(customer); db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult addCustomer(customer_tbl ct) { AspNetUser aspNetUser = new AspNetUser(); if (ModelState.IsValid) { ct.status = true; // ct.password = Convert.ToString("1234"); ct.date_added = DateTime.Now; //this work not complate connect to AspNetUser tabel and pass data on this table ////add data in AspNetUser table //aspNetUser.Email = ct.email; //aspNetUser.UserName = ct.firstname; //db.AspNetUsers.Add(aspNetUser); //db.SaveChanges(); //var v = db.AspNetUsers.Find(aspNetUser.Id); //ct.aspnetuserid = v.Id; db.customer_tbl.Add(ct); db.SaveChanges(); message = "Customer Created Succesfully"; status = true; } else { message = "There asre some problems,Try Agien"; } TempData["message"] = message; TempData["Status"] = status; return(RedirectToAction("customer")); }
public ActionResult Checkout(checkOut couts) { int cID; //customer object customer_tbl ctbl = new customer_tbl(); //address object address_tbl atbl = new address_tbl(); if (ModelState.IsValid) { //get user email form var user = adb.Users.Find(couts.aspnetuserid); //save customer ctbl.lastname = couts.lastname; ctbl.firstname = couts.firstname; ctbl.email = couts.email; ctbl.newsletter = true; ctbl.telephone = couts.telephone; ctbl.aspnetuserid = couts.aspnetuserid; //save addrerss atbl.address_2 = couts.customerAddress; atbl.firstname = couts.firstname; atbl.lastname = couts.lastname; atbl.shepingAddress = couts.shiping_Address; atbl.SheppingPhoneNumber = couts.shippingPhoneNumber; if ((couts.customer_id == null || couts.customer_id == 0) && (couts.address_id == null || couts.address_id == 0)) { //for new customer ctbl.date_added = DateTime.Now; //save in custeomer database db.customer_tbl.Add(ctbl); db.SaveChanges(); //get user id var c = db.customer_tbl.Find(ctbl.customer_id); //save address in database cID = c.customer_id; atbl.customer_id = cID; db.address_tbl.Add(atbl); db.SaveChanges(); } else { ctbl.customer_id = couts.customer_id; db.Entry(ctbl).State = EntityState.Modified; db.SaveChanges(); cID = ctbl.customer_id; atbl.customer_id = cID; atbl.address_id = Convert.ToInt32(couts.address_id); db.Entry(atbl).State = EntityState.Modified; db.SaveChanges(); } //user identiiy field user.PhoneNumber = couts.telephone; user.UserName = couts.firstname; adb.Entry(user).State = EntityState.Modified; adb.SaveChanges(); //get the payment method if (couts.shipping_id != null) { var s = db.payment_method_tbl.Find(couts.shipping_id); couts.belingMethod = s.title; couts.sAmount = Convert.ToDecimal(s.amount); couts.totaltaka += Convert.ToDouble(s.amount); } //get the shipping method if (couts.sid != null) { var s = db.shipping_method.Find(couts.sid); couts.shipping_method = s.Name; } //now start play with order //create order_tbl object order_tbl otbl = new order_tbl(); //save data in order_tbl otbl.customer_id = cID; otbl.date_added = DateTime.Now; otbl.email = couts.email; otbl.firstname = couts.firstname; otbl.lastname = couts.lastname; otbl.payment_address_1 = couts.customerAddress; otbl.payment_method = couts.belingMethod; otbl.payment_telephone = couts.telephone; otbl.shipping_address_1 = couts.shiping_Address; otbl.shipping_telephone = couts.shippingPhoneNumber; otbl.total = Convert.ToDecimal(couts.totaltaka); otbl.amont = couts.sAmount; otbl.shipping_method = couts.shipping_method; db.order_tbl.Add(otbl); db.SaveChanges(); //get otbl id //get order table id var order = db.order_tbl.Find(otbl.order_id); //next save prodect data in product order table order_product_tbl optbl = new order_product_tbl(); var ucart = db.userCart_tbl.Where(a => a.userID == user.Id).ToList(); foreach (var u in ucart) { optbl.order_id = order.order_id; optbl.product_id = u.product_ID; optbl.quantity = u.Quantity; optbl.dicount = u.discountPrice; optbl.price = u.varintPrice + u.mainPrice; optbl.total = u.totalPrice; optbl.name = u.productName; optbl.varints = u.pvvalueID; //save single product db.order_product_tbl.Add(optbl); db.SaveChanges(); ////get order_product tbl //var o = db.order_product_tbl.Find(optbl.order_product_id); //if (o.varints != null || o.varints != "null") //{ // List<int> s = JsonConvert.DeserializeObject<List<int>>(o.varints); // if (s != null) // { // foreach (var i in s) // { // //update varinat unit // var pvv = db.product_variant_value.Find(i); // pvv.quentity -= u.Quantity; // db.Entry(pvv).State = EntityState.Modified; // db.SaveChanges(); // } // } //} ////update product quantity //var p = db.product_tbl.Find(u.product_ID); //p.quantity -= u.Quantity; //db.Entry(p).State = EntityState // .Modified; //db.SaveChanges(); } //delete cart table data foreach (var d in ucart) { db.userCart_tbl.Remove(d); db.SaveChanges(); } //add successfully message message = "Your Order Is Successfully Complete. We Contect YOu Very Soon Thank you"; //update quantity } else { message = "Insert All Data"; } TempData["message"] = message; Session["cart"] = null; return(RedirectToAction("Checkout")); }