public ActionResult DeleteConfirmed(int id) { TFDBLibrary.producttbl producttbl = db.producttbl.Find(id); db.producttbl.Remove(producttbl); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult SendProductGrade(int pid, int?grade) { string userid = HttpContext.User.Identity.GetUserId(); TFDBLibrary.TakeFiveDBEntities db = new TFDBLibrary.TakeFiveDBEntities(); productgrade product = new productgrade(); product.pid = pid; product.grade = Convert.ToInt32(grade); product.mid = userid; db.productgrade.Add(product); db.SaveChanges(); var query = from c in db.productgrade where c.pid == pid select c; int membernum = 0; int totalgrade = 0; foreach (var v in query) { membernum++; totalgrade += Convert.ToInt32(v.grade); } if (membernum == 0) { ViewBag.membernum = membernum; ViewBag.grade = 0; } else { ViewBag.membernum = membernum; ViewBag.grade = totalgrade / membernum; db.producttbl.Find(pid).score = totalgrade / membernum; db.SaveChanges(); } return(PartialView("_Grade")); }
public int ChangeUserNote(int nid, string title, string content) { TFDBLibrary.TakeFiveDBEntities db = new TFDBLibrary.TakeFiveDBEntities(); var note = db.note.Find(nid); note.n_title = title; note.n_content = content; db.SaveChanges(); var query = from c in db.note where c.n_id == nid select new { c.p_id }; int pid = Convert.ToInt32(query.First().p_id); return(pid); }
public ActionResult Index(OrderViewModel orderView) { if (ModelState.IsValid) { var userId = HttpContext.User.Identity.GetUserId(); var currentCart = Models.Cart.Operation.GetCurrentCart(); List <CartItem> items = currentCart.GetCartItems(); Decimal totalPrice; totalPrice = currentCart.TotalAmount; //0 現金 //1 信用卡 PaymentEntity pe = new PaymentEntity(); int payId; payId = pe.Insert(orderView, userId, totalPrice, 1); BuyItemDetailEntify be = new BuyItemDetailEntify(); Boolean isInserted; isInserted = be.Insert(items, userId, payId); TFDBLibrary.TakeFiveDBEntities db = new TFDBLibrary.TakeFiveDBEntities(); foreach (var item in items) { db.producttbl.Find(item.Id).state += 1; } db.SaveChanges(); //移除購物車Session資料 HttpContext.Session.Remove("Cart"); //轉至訂單完成頁面 return(RedirectToAction("FinishOrdered")); //string msg; //msg=PrintOrderViewContent(orderView); //return Content(msg); } // todo error page return(Content("Error!")); //return View(); }
//[ValidateAntiForgeryToken] public ActionResult SendMsg(string id) { string[] msg = id.Split('/'); discuss model = new discuss(); model.p_id = Convert.ToInt32(msg[0]); model.d_content = msg[1]; var ID = HttpContext.User.Identity.GetUserId(); if (ID == null) { return(RedirectToAction("Login", "Account")); } int pid = Convert.ToInt32(model.p_id); TFDBLibrary.TakeFiveDBEntities db = new TFDBLibrary.TakeFiveDBEntities(); model.Id = ID; // model.d_crateDate =Convert.ToString( DateTime.Now.ToLocalTime()); model.d_crateDate = DateTime.Now.ToShortDateString(); db.discuss.Add(model); db.SaveChanges(); //var query = from c in db.producttbl.AsEnumerable() // where c.pid ==pid // select new TabkeFiveWebApplication.Models.ViewModels.ProductViewModels // { // PId = c.pid, // SelectedKinds =Convert.ToInt32( c.kind), // SelectedCategories = Convert.ToInt32(c.category), // MId = c.mid, // Intro = c.intro, // Price = Convert.ToInt32 (c.price), // State = Convert.ToInt32(c.state), // Score = Convert.ToInt32(c.score) // }; //return RedirectToAction("View", "ShoppingCart", new { id = pid }); //var query = from c in db.discuss // where c.p_id == model.p_id // select c; //return PartialView("_Discuss",query); return(Content(msg[0])); }
public int SendtoNote(string title, double?videotime, string content, int pid) { TFDBLibrary.TakeFiveDBEntities db = new TFDBLibrary.TakeFiveDBEntities(); var query = from c in db.producttbl where c.pid == pid select new { c.name }; string productname = query.Count() > 0 ? query.First().name:string.Empty; note model = new note(); model.n_title = title; model.n_content = Convert.ToString(content); model.p_id = pid; model.videotime = videotime; model.create_time = DateTime.Now.ToShortDateString(); model.mid = HttpContext.User.Identity.GetUserId(); model.p_name = productname; db.note.Add(model); db.SaveChanges(); return(pid); }