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 async Task <bool> GetUserLogin(string user) { var serviceLogin = new ServiceLogin(); bool result = await serviceLogin.GetUserLogin(user); return(result); }
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 async Task <string> GetPerfisCombo() { var service = new ServiceLogin(); var jsonstring = await service.GetPerfisCombo(); if (jsonstring == "[]") { return("Null"); } else { return(jsonstring); } }
public async Task <string> GetUserCookie(string user) { var service = new ServiceLogin(); var jsonstring = await service.GetUserCookie(user); if (jsonstring == "[]") { return("Null"); } else { return(jsonstring); } }
private void btnLogin_Click(object sender, EventArgs e) { if (ServiceLogin.Login(txbUserName.Text, txbPassword.Text)) { fManage fManage = new fManage(); this.Hide(); fManage.ShowDialog(); this.Show(); txbPassword.Text = ""; } else { MessageBox.Show("Sai mật khẩu hoặc tên đăng nhập", "Thông báo!!!"); } }
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 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 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")); }
/// <summary> /// pre-revison of the username and password - connected with the errorporvider /// </summary> /// <returns>true = good / false = not acceptable</returns> public bool posiblyGoodUsernamePwdPair() { serviceLogin = new ServiceLogin(parentLoginWindow, dbci); try { serviceLogin.reviseTheAutenticityOfUserNPwd(txtbName.Text, txtbPwd.Text); return(true); } catch (ErrorLogUsernameFormat euf) { errorMessage = "Nem megfelelő felhasználónév vagy jelszó"; elementWithProblem = txtbName; return(false); } catch (ErrorLogPassContent epc) { errorMessage = "Nem megfelelő felhasználónév vagy jelszó"; elementWithProblem = txtbName; return(false); } }
//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")); }
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()); }