public ActionResult Register(Customer cus) { if (string.IsNullOrEmpty(cus.CustomerLoginName)) { ViewBag.Message2 = "請填寫帳號"; return(View("Register", cus)); } if (string.IsNullOrEmpty(cus.CustomerPassword)) { ViewBag.Message3 = "請填寫密碼"; return(View("Register", cus)); } var Customer = db.Customers .Where(c => c.CustomerLoginName == cus.CustomerLoginName) .FirstOrDefault(); if (Customer == null) { Guid userGuid = Guid.NewGuid(); cus.CustomerGuid = userGuid; cus.CustomerPassword = PasswordSecurity.HashSHA1(cus.CustomerPassword + userGuid); db.Customers.Add(cus); db.SaveChanges(); return(RedirectToAction("RegisterOk", cus)); } ViewBag.Message = "此帳號己有人使用,註冊失敗"; return(View()); }
public ActionResult Customerservice2(Opinion op) { op.OpinionFeedbackTime = DateTime.Now.ToString("yyyyMMdd HH:mm"); db.Entry(op).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Customerservice")); }
public ActionResult AddItem(Product pro) { if (Request["OkOrCancel"] == "Cancel") { return(RedirectToAction("Shelf")); } System.IO.Directory.CreateDirectory(@"C:\final-project\pet_box\pet_box\product_images\site_product\product"); var f = Request.Files[0]; if (f.ContentLength >= 0) { f.SaveAs(@"C:\final-project\pet_box\pet_box\product_images\site_product\product\" + f.FileName); } pro.ProductImageLocation = "/product_images/site_product/product/" + f.FileName; db.Products.Add(pro); db.SaveChanges(); return(RedirectToAction("Shelf")); }
public ActionResult DeliveryInfo(DeliveryInfoViewModel divm) { // check the list passed List <ShoppingCartObjectModel> itemObjList = new List <ShoppingCartObjectModel>(); itemObjList = TempData["itemList"] as List <ShoppingCartObjectModel>; TempData.Keep("itemList"); int customerIdInt = Convert.ToInt32(Session["CustomerID"]); if (Request.Form["okOrCancel"] == "ok") { // update Customers // 1 is non-member. //if (itemObjList[0].CustomerID != 1) { if (customerIdInt != 1) { //int myInt = Convert.ToInt32(Session["CustomerID"]); var customerDatabase = db.Customers .Where(x => x.CustomerID == customerIdInt) .FirstOrDefault(); customerDatabase.CustomerAddress = divm.customer.CustomerAddress; customerDatabase.CustomerEmail = divm.customer.CustomerEmail; customerDatabase.CustomerMobilePhone = divm.customer.CustomerMobilePhone; customerDatabase.CustomerName = divm.customer.CustomerName; } else { divm.customer.CustomerRole = 2; db.Customers.Add(divm.customer); } // create Order Order newOrder = new Order(); newOrder.CustomerID = customerIdInt; newOrder.OrderDateTime = DateTime.Now.ToString("yyyyMMdd HH:mm"); newOrder.OrderShipAddress = divm.customer.CustomerAddress; db.Orders.Add(newOrder); // create OrderDetails foreach (ShoppingCartObjectModel item in itemObjList) { OrderDetail newOrderDetail = new OrderDetail(); newOrderDetail.OrderID = newOrder.OrderID; newOrderDetail.ProductID = item.ProductID; newOrderDetail.Quantity = item.Quantity; newOrderDetail.Discount = item.Discount; newOrderDetail.UnitPrice = item.UnitPrice; db.OrderDetails.Add(newOrderDetail); } db.SaveChanges(); // decrease quanty in table Products for (int i = 0; i < itemObjList.Count(); i++) { int itemId = itemObjList[i].ProductID; int itemQuantity = itemObjList[i].Quantity; var productDatabase = db.Products .Where(x => x.ProductID == itemId) .FirstOrDefault(); productDatabase.ProductQuantity = productDatabase.ProductQuantity - itemQuantity; } db.SaveChanges(); return(RedirectToAction("OrderSuccess")); } return(RedirectToAction("ShoppingCart")); }