public ActionResult SerachByUserName(string name) { string searchUserId = null; using (Models.UserEntities db = new Models.UserEntities()) //查詢目前網站使用者暱稱符合UserName的UserId { searchUserId = (from s in db.AspNetUsers where s.UserName == name select s.Id).FirstOrDefault(); } if (!String.IsNullOrEmpty(searchUserId)) { using (Models.ItemEntities db = new Models.ItemEntities()) //如果有存在UserId則將此UserId的所有訂單找出 { var result = (from s in db.Orders where s.UserId == searchUserId select s).ToList(); return(View("Index", result)); } } else { return(View("Index", new List <Models.Order>())); } }
public ActionResult Edit(Models.Product postinfo) { if (this.ModelState.IsValid) { using (Models.ItemEntities db = new Models.ItemEntities()) { var result = (from s in db.Products where s.Id == postinfo.Id select s).FirstOrDefault(); result.Name = postinfo.Name; result.PublishDate = postinfo.PublishDate; result.Status = postinfo.Status; result.Price = postinfo.Price; result.Quantity = postinfo.Quantity; result.CategoryID = postinfo.CategoryID; result.Description = postinfo.Description; result.DefaultImageId = postinfo.DefaultImageId; result.DefaultImageName = postinfo.DefaultImageName; db.SaveChanges(); TempData["ResultMsg"] = string.Format("商品[{0}]成功修改", postinfo.Name); return(RedirectToAction("Index")); } } else { return(View(postinfo)); } }
[Authorize] // 登入會員才可留言 public ActionResult AddComment(int id, string Content) { var userId = HttpContext.User.Identity.GetUserId(); //取得目前登入使用者Id var currentDateTime = DateTime.Now; var comment = new Models.ProductCommet() { ProductId = id, Content = Content, UserId = userId, CreateDate = currentDateTime, UserName = User.Identity.GetUserName() }; using (Models.ItemEntities db = new Models.ItemEntities()) { db.ProductCommets.Add(comment); db.SaveChanges(); } return(RedirectToAction("Details", new { id = id })); }
public ActionResult Index() { using (Models.ItemEntities db = new Models.ItemEntities()) { var result = (from s in db.Products select s).ToList(); return(View(result)); } }
public ActionResult ShowAll() { using (Models.ItemEntities db = new Models.ItemEntities()) { var result = (from s in db.Orders select s).ToList(); return(View("Index", result)); } }
public ActionResult MyOrder() { var UserId = HttpContext.User.Identity.GetUserId(); using (Models.ItemEntities db = new Models.ItemEntities()) { var result = (from s in db.Orders where s.UserId == UserId select s).ToList(); return(View(result)); } }
public ActionResult MyOrderDetail(int id) { using (Models.ItemEntities db = new Models.ItemEntities()) { var result = (from s in db.OrderDetails where s.OrderId == id select s).ToList(); if (result.Count == 0) { return(RedirectToAction("Index")); } else { return(View(result)); } } }
public ActionResult Edit(int id) { using (Models.ItemEntities db = new Models.ItemEntities()) { var result = (from s in db.Products where s.Id == id select s).FirstOrDefault(); if (result != default(Models.Product)) //驗證是否有資料存在 { return(View(result)); } else { TempData["ResultMsg"] = "資料有誤"; return(RedirectToAction("Index")); } } }
public ActionResult Details(int id) { using (Models.ItemEntities db = new Models.ItemEntities()) { var result = (from s in db.Products where s.Id == id select s).FirstOrDefault(); if (result == default(Models.Product)) { return(RedirectToAction("Index")); } else { return(View(result)); } } }
public ActionResult Creat(Models.Product postinfo) { if (this.ModelState.IsValid) { using (Models.ItemEntities db = new Models.ItemEntities()) { postinfo.DefaultImageName = postinfo.DefaultImageName + ".png"; db.Products.Add(postinfo); db.SaveChanges(); TempData["ResultMsg"] = string.Format("商品[{0}]成功建立", postinfo.Name); } return(RedirectToAction("Index")); } ViewBag.ResultMessage = "資料有誤"; return(View(postinfo)); }
public ActionResult Delete(int id) { using (Models.ItemEntities db = new Models.ItemEntities()) { var result = (from s in db.Products where s.Id == id select s).FirstOrDefault(); if (result != default(Models.Product)) //資料判斷有無 { db.Products.Remove(result); db.SaveChanges(); TempData["ResultMsg"] = string.Format("商品[{0}]成功刪除", result.Name); return(RedirectToAction("Index")); } else { TempData["ResultMsg"] = "指定資料不存在"; return(RedirectToAction("Index")); } } }
public ActionResult Index() { var userName = User.Identity.GetUserName(); if (userName == "Admin") { using (Models.ItemEntities db = new Models.ItemEntities()) { var result = (from s in db.Orders select s).ToList(); return(View(result)); } } else { return(Content("<script>alert('權限不足 滾啦!');history.go(-1);</script>")); //return Content("<script>alert('權限不足 滾啦!');window.location.href='../Home/Index';</script>"); } }
public ActionResult Index() { var userName = User.Identity.GetUserName(); if (userName == "Admin") { List <Models.Product> result = new List <Models.Product>(); ViewBag.ResultMessage = TempData["ResultMsg"]; using (Models.ItemEntities db = new Models.ItemEntities()) { result = (from s in db.Products select s).ToList(); return(View(result)); } } else { return(Content("<script>alert('權限不足 滾啦!');history.go(-1);</script>")); //return Content("<script>alert('權限不足 滾啦!');window.location.href='../Home/Index';</script>"); //return Redirect("/Home/Index"); } }
public ActionResult Index(Models.OrderModel.Ship postback) { if (this.ModelState.IsValid) { var currentcart = Models.Cart.Operation.GetCurrentCart();//取得目前購物車 var userId = HttpContext.User.Identity.GetUserId();//取得登入使用者Id using (Models.ItemEntities db = new Models.ItemEntities()) { var order = new Models.Order() { UserId = userId, RecieverName = postback.RecieverName, RecieverPhone = postback.RecieverPhone, RecieverAddress = postback.RecieverAddress }; db.Orders.Add(order); //加其入Orders資料表後,儲存變更 db.SaveChanges(); var orderDetails = currentcart.ToOrderDetailList(order.Id);//取得購物車中OrderDetai物件 db.OrderDetails.AddRange(orderDetails);//將其加入OrderDetails資料表後,儲存變更 db.SaveChanges(); } var currentCart = Models.Cart.Operation.GetCurrentCart(); currentCart.ClearCart(); return(Redirect("/Order/MyOrder")); } return(View()); }