public ActionResult AddCriteria(string criteriaName) { db.Criteria.Add(new Criterion() { CriteriaName = criteriaName }); db.SaveChanges(); return(RedirectToAction("AllCriteria", "Admin")); //return Json(new { result = true, success = true }, JsonRequestBehavior.AllowGet); }
public ActionResult ChangeInfo(FormCollection data) { var accountID = data["accountID"]; var name = data["nameUser"]; var birthday = DateTime.Parse(data["birthday"]); var phone = data["phone"]; var sex = Int32.Parse(data["sex"]); var province = Int32.Parse(data["province"]); var district = Int32.Parse(data["district"]); using (var db = new QLTroEntities()) { Info accInfo = db.Infoes.SingleOrDefault(p => p.AccountID.Equals(accountID)); if (accInfo != null) { accInfo.Name = name; accInfo.Birthday = birthday; accInfo.Phone = phone; if (sex == 1) { accInfo.Sex = true; } else { accInfo.Sex = false; } accInfo.ProvinceID = province; accInfo.DistrictID = district; db.SaveChanges(); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); } } return(Json(new { success = false }, JsonRequestBehavior.AllowGet)); }
public ActionResult ChangePassWord(FormCollection data) { Account account = null; var acountID = data["accountID"]; var oldPassword = data["currentPassword"]; var newpassword = data["newPassword"]; using (var db = new QLTroEntities()) { account = db.Accounts.Single(p => p.AccountID.Equals(acountID) && p.Password.Equals(oldPassword)); account.Password = newpassword; db.SaveChanges(); } account.Password = ""; Session["account"] = account; return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult SignUp(FormCollection data) { var accountId = data["accountId"]; var password = data["password"]; var userName = data["userName"]; DateTime birthDate = DateTime.Parse(data["birthDate"]); var address = data["address"]; var phone = data["phone"]; var email = data["email"]; var city = data["city"]; var district = data["district"]; bool sex = true; if (data["sex"].Equals("1")) { sex = true; } else { sex = false; } int role = 0; if (data["role"].Equals("1")) { role = 1; } else { role = 2; } using (var db = new QLTroEntities()) { db.Accounts.Add(new Account() { AccountID = accountId, AccountStatusID = 1, Password = password, Role = role }); db.Infoes.Add(new Info() { AccountID = accountId, Name = userName, Sex = sex, Birthday = birthDate, Phone = phone, Email = email, ProvinceID = Int32.Parse(city), DistrictID = Int32.Parse(district) }); db.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public ActionResult ResetPassword(string accountID) { var newpass = RandomHelper.RandomNewPassword(); var email = string.Empty; using (var db = new QLTroEntities()) { var account = db.Accounts.Single(p => p.AccountID.Equals(accountID)); var accountInfo = db.Infoes.Single(p => p.AccountID.Equals(accountID)); email = accountInfo.Email; account.Password = newpass; db.SaveChanges(); string content = System.IO.File.ReadAllText(Server.MapPath("~/Content/Mail/templateEmail.html")); content = content.Replace("{{content}}", "Mật khẩu mới của bạn là: " + newpass); MailHelper.sendMail(email, "Lấy lại mật khẩu", content); } return(Json(new { success = true, result = email }, JsonRequestBehavior.AllowGet)); }
private bool UpdatePostView(string postID) { var result = false; if (!String.IsNullOrEmpty(postID)) { var temp = 0; if (Int32.TryParse(postID, out temp)) { var current = db.Posts.FirstOrDefault(p => p.PostID.Equals(temp)); if (current != null) { current.PostView = current.PostView + 1; db.SaveChanges(); result = true; } } } return(result); }
public ActionResult EmailConfirm(string email) { using (var db = new QLTroEntities()) { // Create Verifition Code var verfiticationCode = Helpers.RandomHelper.RandomVerificationCode().ToString(); ConfirmEmail emC = new ConfirmEmail() { Email = email, Time = DateTime.Now.TimeOfDay, VerificationCode = verfiticationCode }; db.ConfirmEmails.Add(emC); db.SaveChanges(); string content = System.IO.File.ReadAllText(Server.MapPath("~/Content/Mail/templateEmail.html")); content = content.Replace("{{content}}", "Mã xác minh của bạn là: " + verfiticationCode + "<br><br>Mã xác minh có hiệu lực trong vòng 15 phút!"); MailHelper.sendMail(email, "Xác minh tài khoản Email", content); return(Json(new { success = true, exist = true }, JsonRequestBehavior.AllowGet)); } }
public ActionResult RoomDetails(string motelID) { var account = new Account(); if (Session["account"] == null) { return(RedirectToAction("Index", "Home")); } else { account = Session["account"] as Account; if (account.Role == 0) { return(RedirectToAction("AllPost", "Admin")); } else if (account.Role == 2) { return(RedirectToAction("ChangeInfo", "Account")); } } var ID = 0; if (motelID != null) { ID = int.Parse(motelID); } var billExist = db.Bills.SingleOrDefault(p => p.MotelID == ID); if (billExist != null) { var dateCurrent = DateTime.Now; var listBillDetails = db.BillDetails.Where(p => p.BillID == billExist.BillID).ToList(); var n = listBillDetails.Count(); var toDayFinal = listBillDetails[n - 1].ToDay; var period = (dateCurrent - toDayFinal).Value.Days; if (period > 0) { var buildDetails = new BillDetail() { BillID = billExist.BillID, BillStatus = false, FromDay = toDayFinal.Value.AddDays(1), ToDay = toDayFinal.Value.AddDays(31), RoomRates = db.MotelRooms.SingleOrDefault(p => p.MotelID == ID).Price }; db.BillDetails.Add(buildDetails); db.SaveChanges(); } } var x = db.MotelRooms.SingleOrDefault(p => p.MotelID == ID && p.AccountID == account.AccountID); ViewBag.totalPeople = db.Renters.Where(p => p.MotelID == ID).Count(); ViewBag.maxPeople = db.MotelRooms.SingleOrDefault(p => p.MotelID == ID).MaxPeople; if (x != null) { ViewBag.motelID = ID; ViewBag.motelStatus = x.StatusID; account = Session["account"] as Account; var listRenter = db.Renters.Where(p => p.MotelID == ID).ToList(); var bill = db.Bills.SingleOrDefault(p => p.MotelID == ID); var room = db.MotelRooms.SingleOrDefault(p => p.MotelID == ID); var listBillDetails = new List <BillDetail>(); if (bill != null) { listBillDetails = db.BillDetails.Where(p => p.BillID == bill.BillID).ToList(); } RoomDetailsModel roomDetailsModel = new RoomDetailsModel() { Bill = bill, ListRenter = listRenter, MotelRoom = room, ListBillDetail = listBillDetails }; return(View(roomDetailsModel)); } else { return(RedirectToAction("MotelRooms", "User")); } }