public ActionResult Contact(FormCollection form) { string first_name = Request.Form["first_name"]; string last_name = Request.Form["last_name"]; string fullname = null; if (first_name != null && last_name != null) { fullname = first_name + last_name; } string email = Request.Form["email"]; string phone = Request.Form["phone"]; string service = Request.Form["service"]; string description = Request.Form["description"]; //khach hang khong dang nhap. tao tai khoan cho khach hang nhu email va ten ma khach hang nhap vao //mat khau tao mac dinh la sdt cua khach hang dang nhap vao va minh tu kich hoat tai khoan cho no luon Customer customer = new Customer(); if (Session["id_Customer"] == null) { var account = db.Customers.Where(x => x.email.Equals(email)).FirstOrDefault(); if (account != null) { return(new RedirectResult(url: "/Home/Contact?message=invalid_email")); } customer.email = email; customer.password = EncryptPassword.EncryptForPassword(phone); customer.fullname = fullname.ToString(); customer.phone = Convert.ToInt32(phone); customer.address = ""; customer.idCounty = 1; customer.avatar = "Assets/Client/resources/image/" + "customerDefault.jpg"; customer.activated = true; customer.status = true; customer.createdDate = DateTime.Now; customer.modifyDate = DateTime.Now; customer.modifyBy = fullname.ToString(); customer.dayOfBirth = DateTime.Now; customer.roleId = 3; db.Customers.Add(customer); db.SaveChanges(); SendEmail.SendMail("Gửi từ Laundry Store, Xác nhận người dùng ! ", customer.email, " Bạn vừa đăng kí thành công tài khoản tại Laundry Store !" + " Với tên đăng nhập : " + customer.email + " Bạn có thể sử dụng email trên để đăng nhập vào cửa hàng của chúng tôi với mật khẩu là số điện thoại của bạn : " + customer.phone + " " + " Vui lòng truy cập vào đường dẫn dưới đây để cập nhật thông tin tài khoản " + "https://localhost:44335/Account/infoProfile/" + customer.id); } //khach hang co dang nhap tai khoan else { var customerId = int.Parse(Session["id_Customer"].ToString()); customer = db.Customers.Find(customerId); if (customer != null) { customer.email = Session["email_Customer"].ToString(); customer.fullname = Session["username_Customer"].ToString(); customer.modifyDate = DateTime.Now; customer.modifyBy = Session["username_Customer"].ToString(); db.SaveChanges(); } } Order order = new Order(); order.customerId = customer.id; order.orderDate = DateTime.Now; order.paymentStatus = "doing"; order.description = description; order.statusId = 2; order.createdBy = customer.fullname; order.status = true; db.Orders.Add(order); db.SaveChanges(); //insert table barcodes Barcode barcode = new Barcode(); barcode.orderId = order.id; barcode.codeName = RandomBarCodes.RandomBarCode(); barcode.createdDate = DateTime.Now; barcode.createdBy = fullname.ToString(); db.Barcodes.Add(barcode); db.SaveChanges(); OrderDetail orderDetail = new OrderDetail(); orderDetail.orderId = order.id; orderDetail.productId = Convert.ToInt32(service); orderDetail.status = true; db.OrderDetails.Add(orderDetail); db.SaveChanges(); return(new RedirectResult(url: "/Home/Contact?message=contactSuccess")); }
public JsonResult purchase(string fullName, string email, int phone, string county, string address, string description) { //khach hang khong dang nhap Customer customer = new Customer(); if (Session["id_Customer"] == null) { customer.email = email; customer.password = EncryptPassword.EncryptForPassword(phone.ToString()); customer.fullname = fullName; customer.phone = phone; customer.address = address; customer.avatar = "Assets/Client/resources/image/" + "customerDefault.jpg"; customer.idCounty = Int32.Parse(county); customer.activated = true; customer.status = true; customer.createdDate = DateTime.Now; customer.modifyDate = DateTime.Now; customer.modifyBy = fullName; customer.dayOfBirth = DateTime.Now; customer.roleId = 3; db.Customers.Add(customer); db.SaveChanges(); SendEmail.SendMail("Gửi từ Laundry Store, Xác nhận người dùng ! ", customer.email, " Bạn vừa đăng kí thành công tài khoản tại Laundry Store !" + " Với tên đăng nhập : " + customer.email + " Bạn có thể sử dụng email trên để đăng nhập vào cửa hàng của chúng tôi với mật khẩu là số điện thoại của bạn : " + customer.phone + " " + " Vui lòng truy cập vào đường dẫn dưới đây để cập nhật thông tin tài khoản " + "https://localhost:44335/Account/infoProfile/" + customer.id); } else { var customerId = int.Parse(Session["id_Customer"].ToString()); customer = db.Customers.Find(customerId); if (customer != null) { customer.email = email; customer.fullname = fullName; customer.phone = phone; customer.address = address; customer.idCounty = Int32.Parse(county); customer.modifyDate = DateTime.Now; customer.modifyBy = Session["username_Customer"].ToString(); db.SaveChanges(); } } //them don hang vao trong order Order order = new Order(); order.customerId = customer.id; order.orderDate = DateTime.Now; order.address = address; order.paymentMethodId = 1; order.paymentStatus = "doing"; order.amount = totalQuantity(); order.description = description; order.statusId = 2; order.createdBy = customer.fullname; order.shippingId = 1; order.totalDebt = 0; order.status = true; double?total = totalMoney(); order.totalOrder = Convert.ToInt64(total); db.Orders.Add(order); db.SaveChanges(); //insert table barcodes Barcode barcode = new Barcode(); barcode.orderId = order.id; barcode.codeName = RandomBarCodes.RandomBarCode(); barcode.createdDate = DateTime.Now; barcode.createdBy = fullName; db.Barcodes.Add(barcode); db.SaveChanges(); //them don hang vao chi tiet don hang List <CartItem> listCart = getCart(); foreach (CartItem item in listCart) { OrderDetail orderDetail = new OrderDetail(); orderDetail.orderId = order.id; orderDetail.productId = Convert.ToInt32(item.productId); orderDetail.discount = item.discount; orderDetail.price = item.price; orderDetail.type = item.type; orderDetail.status = true; orderDetail.totalPrice = Convert.ToInt64(item.total); db.OrderDetails.Add(orderDetail); db.SaveChanges(); } Session["cart"] = null; if (Session["id_Customer"] == null) { return(Json(1, JsonRequestBehavior.AllowGet)); } return(Json(2, JsonRequestBehavior.AllowGet)); }