public FileResult showphoto(int id) { farmarEntities1 db = new farmarEntities1(); byte[] data = db.products.Find(id).picture; return(File(data, "image/jpeg")); }
//新增一筆Product,使用ProductId public bool AddProduct(int ProductId, int quantity) { var findItem = this.cartItems .Where(s => s.Id == ProductId) .Select(s => s) .FirstOrDefault(); //判斷相同Id的CartItem是否已經存在購物車內 if (findItem == default(Models.Cart.CartItem)) { //不存在購物車內,則新增一筆 using (farmarproject2.Models.farmarEntities1 db = new farmarEntities1()) { var product = (from s in db.products where s.productid == ProductId select s).FirstOrDefault(); if (product != default(farmarproject2.Models.product)) { this.AddProduct(product, quantity); } } } else { //存在購物車內,則將商品數量累加 findItem.Quantity = findItem.Quantity + quantity; } return(true); }
public ActionResult AddItem([Bind(Include = "productid,productname,unitprice,unitstock,description,picture,picture1,picture2,category,category_multiple,sell_id")] product product) { farmarEntities1 db = new farmarEntities1(); if (ModelState.IsValid) { if (Request.Files["File1"] != null) { byte[] data = null; using (BinaryReader br = new BinaryReader(Request.Files["File1"].InputStream)) { data = br.ReadBytes(Request.Files["File1"].ContentLength); } product.picture = data; } ServiceLogin service = new ServiceLogin() { userID = "famar123", LoginTime = DateTime.Now, ContentA = "新增商品", State = "新增", Type = "商品資料" }; db.ServiceLogins.Add(service); product.user_email = "管理員"; product.sale = 0; db.products.Add(product); db.SaveChanges(); return(Json("OK")); } return(Json("NO")); }
public ActionResult SearchOrderBySell() { farmarEntities1 db = new farmarEntities1(); var orders = from c in db.orders where c.sell_id == User.Identity.Name select c; return(View(orders)); }
public ActionResult Pay(Int32 order_id) { farmarEntities1 db = new farmarEntities1(); var orderdetail = (from m in db.orders where m.order_id == order_id select m).FirstOrDefault(); string result = ProcessPayment(orderdetail); return(Content(result)); }
public ActionResult ItemEditView(int id = 0) { if (id == 0) { return(View("Index")); } global::farmarproject2.Models.farmarEntities1 farmar = new farmarEntities1(); product user = farmar.products.Where(o => o.productid == id).SingleOrDefault(); return(View(user)); }
public ActionResult minuscate(int order_id) { farmarEntities1 db = new farmarEntities1(); order o = db.orders.Where(a => a.order_id == order_id).Select(b => b).SingleOrDefault(); o.date = DateTime.Now.ToString(); o.status = "付款成功"; db.Entry(o).State = EntityState.Modified; db.SaveChanges(); return(null); }
public ActionResult FLogin(ServiceAccount model, string returnUrl) { if (model.Account == null || model.Psword == null) { ModelState.AddModelError("", "登入失敗。"); return(View(model)); } farmarEntities1 farmarEntities1 = new farmarEntities1(); var tempPS = farmarEntities1.ServiceAccounts.Where(p => p.Account == model.Account).Select(a => a.Psword).SingleOrDefault(); if (tempPS == model.Psword) { TempUser = model.Account; ServiceLogin service = new ServiceLogin() { userID = TempUser, LoginTime = DateTime.Now, ContentA = $"{model.Account}登入", State = "登入", Type = "用戶" }; farmarEntities1.ServiceLogins.Add(service); farmarEntities1.SaveChanges(); TempData["TempName"] = model.Account; //存取cookie if (Request.Cookies["ServerID"] == null) { HttpCookie Cookie = new HttpCookie("ServerID", model.Account); Cookie.Expires = DateTime.Now.AddDays(1); //設置Cookie到期時間 HttpContext.Response.Cookies.Add(Cookie); } else { Request.Cookies.Remove("ServerID"); //-------- HttpCookie Cookie = new HttpCookie("ServerID", model.Account); Cookie.Expires = DateTime.Now.AddDays(1); //設置Cookie到期時間 HttpContext.Response.Cookies.Add(Cookie); } return(RedirectToAction("Index", "Serice")); } else { ModelState.AddModelError("", "登入失敗。"); return(View(model)); } }
public async Task <ActionResult> ResetPs(AspNetUser user) { if (ModelState.IsValid) { string password = "******"; string[] p1 = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; string[] p2 = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }; Random random = new Random(); for (int i = 0; i <= 4; i++) { var temp = random.Next(0, 2); var temp2 = random.Next(0, 10); if (temp == 0) { password = $"{password}{p1[temp2]}"; } else { password = $"{password}{p2[temp2]}"; } } Crypto.HashPassword(password); farmarEntities1 farmar = new farmarEntities1(); AspNetUser tempuser = farmar.AspNetUsers.Where(o => o.Email == user.Email).SingleOrDefault(); tempuser.PasswordHash = Crypto.HashPassword(password); farmar.Entry(tempuser).State = EntityState.Modified; List <string> mailname = new List <string>(); mailname.Add(user.Email); await SendMailByGmail(mailname, "碼農是好農密碼重設通知", MailMessage("密碼已重設", $"您的碼農是好農帳戶新密碼為:{password}", user.FamName)); ServiceLogin service = new ServiceLogin() { userID = "famar123", LoginTime = DateTime.Now, ContentA = $"{user.Email}會員的密碼更改", State = "修改", Type = "會員資料" }; farmar.ServiceLogins.Add(service); farmar.SaveChanges(); HttpCookie Cookie = new HttpCookie(".AspNet.ApplicationCookie"); Cookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(Cookie); return(Json("ok")); } return(HttpNotFound()); }
public ActionResult Index(ship postback, string sell_id) { if (this.ModelState.IsValid) { //取得目前購物車 var currentcart = Carts.Models.Cart.Operation.GetCurrentCart(); //取得目前登入使用者Id var userId = User.Identity.GetUserName(); using (farmarEntities1 db = new farmarEntities1()) { //建立Order物件 order order = new order() { buy_id = userId, buy_Name = postback.buy_Name, buy_Phone = postback.buy_phone, buy_Address = postback.buy_Address, order_category = "非預購", build_time = DateTime.Now, sell_id = sell_id, status = "未付款", }; //加其入Orders資料表後,儲存變更 db.orders.Add(order); try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { throw ex; } //取得購物車中OrderDetai物件 var orderDetails = currentcart.ToOrderDetailList(order.order_id); var orders = from c in orderDetails where c.sell_id == sell_id select c; //將其加入OrderDetails資料表後,儲存變更 db.order_detail.AddRange(orders); db.SaveChanges(); var currentCart = Operation.GetCurrentCart(); currentCart.Removesell_id(sell_id); } return(RedirectToAction("Orders")); } return(View()); }
public ActionResult pack(int?order_detail_id, int?product_id, int quintity) { farmarEntities1 db = new farmarEntities1(); product c = db.products.Where(a => a.productid == product_id).Select(b => b).SingleOrDefault(); c.unitstock -= quintity; c.sale += quintity; db.Entry(c).State = EntityState.Modified; db.SaveChanges(); order_detail o = db.order_detail.Where(a => a.order_detail_id == order_detail_id).Select(b => b).SingleOrDefault(); o.status = "成功出貨"; db.SaveChanges(); return(RedirectToAction("Index", "Home", null)); }
public ActionResult getproductchart() { var sum = 0; float[] array1 = new float[] { 0, 0, 0, 0, 0 }; farmarEntities1 farmar = new farmarEntities1(); var Oid = farmar.orders.Where(o => o.status == "付款成功").Select(z => z.order_id); foreach (var x in Oid) { var l1 = farmar.order_detail.Where(a => a.order_id == x).ToList(); foreach (var y in l1) { var q = farmar.products.Where(z => y.productid == z.productid).Select(o => o.category).FirstOrDefault(); switch (q) { case "肉類": array1[0] += y.quiantity; break; case "海鮮": array1[1] += y.quiantity; break; case "蔬果": array1[2] += y.quiantity; break; case "調味品": array1[3] += y.quiantity; break; case "五穀雜糧": array1[4] += y.quiantity; break; } sum += y.quiantity; } } for (int i = 0; i < array1.Length; i++) { array1[i] = array1[i] / sum * 100; } var List1 = array1.ToList(); return(Json(List1, JsonRequestBehavior.AllowGet)); }
public ActionResult ItemEdit(product product) { farmarEntities1 db = new farmarEntities1(); product tempuser = db.products.Where(o => o.productid == product.productid).Select(p => p).SingleOrDefault(); if (ModelState.IsValid) { if (Request.Files["File1"].FileName != "") { byte[] data = null; using (BinaryReader br = new BinaryReader(Request.Files["File1"].InputStream)) { data = br.ReadBytes(Request.Files["File1"].ContentLength); } tempuser.picture = data; } else { tempuser.picture = product.picture; } if (product.category != null) { tempuser.category = product.category; } tempuser.productname = product.productname; tempuser.unitprice = product.unitprice; tempuser.unitstock = product.unitstock; tempuser.description = product.description; tempuser.user_email = product.user_email; db.Entry(tempuser).State = EntityState.Modified; ServiceLogin service = new ServiceLogin() { userID = "famar123", LoginTime = DateTime.Now, ContentA = $"編號{product.productid}商品-資料更改", State = "修改", Type = "商品資料" }; db.ServiceLogins.Add(service); db.SaveChanges(); return(Json("yes")); } return(HttpNotFound()); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // 這不會計算為帳戶鎖定的登入失敗 // 若要啟用密碼失敗來觸發帳戶鎖定,請變更為 shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: if (Request.Cookies["MemberID"] == null) { HttpCookie Cookie = new HttpCookie("MemberID", model.Email); Cookie.Expires = DateTime.Now.AddDays(1); //設置Cookie到期時間 HttpContext.Response.Cookies.Add(Cookie); } else { Request.Cookies.Remove("MemberID"); //-------- HttpCookie Cookie = new HttpCookie("MemberID", model.Email); Cookie.Expires = DateTime.Now.AddDays(1); //設置Cookie到期時間 HttpContext.Response.Cookies.Add(Cookie); } global::farmarproject2.Models.farmarEntities1 farmar = new farmarEntities1(); TempName.name = farmar.AspNetUsers.Select(o => o).Where(c => c.Email == model.Email).SingleOrDefault().UserIg; TempName.username = farmar.AspNetUsers.Select(o => o).Where(c => c.Email == model.Email).SingleOrDefault().FamName; return(RedirectToAction("homepage", "Home")); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "登入失敗。"); return(View(model)); } }
public ActionResult Addcomment(int productid, string content) { var userId = User.Identity.Name; var comment = new Models.comment() { ProductID = productid, Contents = content, UserId = userId, CreateDate = DateTime.Now }; using (farmarEntities1 db = new farmarEntities1()) { db.comments.Add(comment); db.SaveChanges(); } return(RedirectToAction("Details", new { id = productid })); }
public ActionResult EditUser(AspNetUser user, HttpPostedFileBase File1 = null) { farmarEntities1 db = new farmarEntities1(); if (ModelState.IsValid) { AspNetUser tempuser = db.AspNetUsers.Where(o => o.Email == user.Email).Select(p => p).SingleOrDefault(); tempuser.FamName = user.FamName; tempuser.PhoneNumber = user.PhoneNumber; var tempimg = ""; //換圖 if (File1 != null) { string filejpg = Path.GetExtension(File1.FileName); tempimg = $"{user.Email}{filejpg}"; string routeimg = Path.Combine(Server.MapPath("~/image"), $"{user.Email}{filejpg}"); File1.SaveAs(routeimg); tempuser.UserIg = tempimg; TempName.name = tempimg; } else { tempuser.UserIg = user.UserIg; TempName.name = user.UserIg; } db.Entry(tempuser).State = EntityState.Modified; ServiceLogin service = new ServiceLogin() { userID = "famar123", LoginTime = DateTime.Now, ContentA = $"{user.Email}會員的資料更改", State = "修改", Type = "會員資料" }; db.ServiceLogins.Add(service); db.SaveChanges(); TempName.username = user.FamName; return(Json("yes")); } return(HttpNotFound()); }
public ActionResult SAreaDT7() { int[] array1 = new int[] { 0, 0, 0, 0, 0 }; string[] array2 = new string[] { "", "", "", "", "" }; var i = 0; farmarEntities1 farmar = new farmarEntities1(); var l1 = farmar.products.OrderByDescending(o => o.sale).Take(5); foreach (var x in l1) { array1[i] = (int)(x.sale); array2[i] = x.productname; i++; } return(Json(new { array1 = array1, array2 = array2 }, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteItem(product product) { farmarEntities1 db = new farmarEntities1(); product tempuser = db.products.Where(o => o.productid == product.productid).Select(p => p).SingleOrDefault(); ServiceLogin service = new ServiceLogin() { userID = "famar123", LoginTime = DateTime.Now, ContentA = $"編號{product.productid}商品-刪除", State = "刪除", Type = "商品資料" }; db.ServiceLogins.Add(service); db.products.Remove(tempuser); db.SaveChanges(); return(Json("yes")); }
//GET public ActionResult Logout() { global::farmarproject2.Models.farmarEntities1 farmar = new farmarEntities1(); ServiceLogin service = new ServiceLogin() { userID = "famar123", LoginTime = DateTime.Now, ContentA = $"famar123登出", State = "登出", Type = "用戶" }; if (Request.Cookies["ServerID"] != null) { HttpCookie Cookie = new HttpCookie("ServerID"); Cookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(Cookie); } farmar.ServiceLogins.Add(service); farmar.SaveChanges(); return(RedirectToAction("Index", "Home")); }
private int chartkinduse(string dkind, string mon) { int sum = 0; farmarEntities1 farmar = new farmarEntities1(); var q = farmar.orders.Where(o => o.status == "付款成功"); var oid1 = (from s in q where s.date.Substring(5, 2) == mon select s.order_id).ToList(); foreach (var x in oid1) { var l1 = farmar.order_detail.Where(a => a.order_id == x).ToList(); foreach (var y in l1) { var w = farmar.products.Where(z => y.productid == z.productid).FirstOrDefault(); if (w.category == dkind) { sum += y.quiantity; } } } return(sum); }
public async Task <ActionResult> OrderEdit(Serviceorder od) { farmarEntities1 db = new farmarEntities1(); order tempuser = db.orders.Where(o => o.order_id == od.order_id).Select(p => p).SingleOrDefault(); string produt = "~"; if (ModelState.IsValid) { if (od.status != null) { tempuser.status = od.status; } if (od.status == "付款成功") { tempuser.date = DateTime.Now.ToString(); } db.Entry(tempuser).State = EntityState.Modified; ServiceLogin service = new ServiceLogin() { userID = "famar123", LoginTime = DateTime.Now, ContentA = $"編號{od.order_id}定單-資料更改", State = "修改", Type = "訂單資料" }; db.ServiceLogins.Add(service); var T = db.order_detail.Where(o => o.order_id == od.order_id).ToList(); if (od.status == "付款成功") { foreach (var x in T) { var pt = db.products.Where(a => a.productid == x.productid).FirstOrDefault(); if (pt.unitstock >= x.quiantity) { pt.unitstock = pt.unitstock - x.quiantity; } pt.sale += x.quiantity; db.Entry(pt).State = EntityState.Modified; } } else if (od.status == "缺貨中") { foreach (var x in T) { var pt = db.products.Where(a => a.productid == x.productid).FirstOrDefault(); if (pt.unitstock < x.quiantity) { produt = $"{produt}{pt.productname}~"; } } } List <string> MailList = new List <string>(); MailList.Add(od.buy_id); var name = db.AspNetUsers.Where(o => o.Email == od.buy_id).Select(a => a.FamName).FirstOrDefault(); db.SaveChanges(); if (od.status == "付款成功") { await SendMailByGmail(MailList, "碼農是好農交易成功通知", MailMessage("交易明細", $"您的訂單編號{od.order_id}已經完成交易", name)); } else if (od.status == "缺貨中") { await SendMailByGmail(MailList, "碼農是好農缺貨通知", MailMessage("缺貨通知", $"您的訂單編號{od.order_id},商品{produt}庫存不足已取消訂單,待庫存足夠請重新下單", name)); } return(Json("yes")); } return(HttpNotFound()); }