public ActionResult Delete(int id) { Message news = new Message(); if ((user)Session["user"] == null) { return RedirectToAction("Index", "Home"); } else { using (var db = new HotelDBEntities()) { try { reservation toDel = db.reservations.Find(id); db.reservations.Remove(toDel); db.SaveChanges(); news.type = 1; news.text = "Your reservation has been deleted"; return View("User", news); } catch (Exception e) { news.type = 0; news.text = "Unexpected database problem."; return View("User", news); } } } }
// // GET: /Reservation/ public ActionResult Index(int id = 0, int type = 0, string text = null) { Message info = new Message(); info.id = id; info.type = type; info.text = text; info.idStr = Convert.ToString(id); return View(info); }
public ActionResult User(Message info) { if ((user)Session["user"] != null) { if (info.text == null) return View(); else return View(info); } else { return RedirectToAction("Index", "Home"); } }
// // GET: /Home/ public ActionResult Index(int type = 0, string text = null) { if ((type == 0 || type == 1) && text != null) { Message message = new Message(); message.type = type; message.text = text; return View(message); } else { return View(); } }
public ActionResult Forgot(string forgotEmail) { if (Session["user"] != null) { return RedirectToAction("Index", "Home"); } else { Message info = new Message(); if (String.IsNullOrEmpty(forgotEmail)) { info.type = 0; info.text = "You didn't fill the e-mail address field."; } else { using (var db = new HotelDBEntities()) { var user = db.users.FirstOrDefault(u => u.email == forgotEmail); if (user == null) { info.text = "User with such e-mail address doesn't exist."; } else { string newPass = "******"; var crypto = new SimpleCrypto.PBKDF2(); var encrPass = crypto.Compute(newPass); user.password = encrPass; user.password_salt = crypto.Salt; try { db.users.Attach(user); db.Entry(user).Property(p => p.password).IsModified = true; db.Entry(user).Property(p => p.password_salt).IsModified = true; db.SaveChanges(); info.type = 1; info.text = "Your password has been changed on: test123."; } catch (Exception e) { info.text = "Unexpected database error."; } } } } return View(info); } }
public ActionResult Register(string regEmail, string regPass, string regConfPass, string regName, string regSurname, string regCountry, string regBirth) { Message info = new Message(); List<bool> check = new List<bool>(); check.Add(String.IsNullOrEmpty(regEmail)); check.Add(String.IsNullOrEmpty(regPass) || regPass.Length < 6 || regPass.Length > 10); check.Add(String.IsNullOrEmpty(regConfPass) || regConfPass.Length < 6 || regConfPass.Length > 10); check.Add(String.Compare(regConfPass, regPass) != 0); check.Add(String.IsNullOrEmpty(regName)); check.Add(String.IsNullOrEmpty(regSurname)); check.Add(String.IsNullOrEmpty(regCountry)); check.Add(String.IsNullOrEmpty(regBirth)); if (check.Contains(true)) { info.text = "You didn't fill correctly all of the fields. "; info.text += "Remember that: password and confirmations must be the same, have between 6-10 marks and birth date of legal age."; info.type = 0; } else { user newUser = new user(); var crypto = new SimpleCrypto.PBKDF2(); var encrPass = crypto.Compute(regPass); newUser.password = encrPass; newUser.password_salt = crypto.Salt; DateTime birthDate = Convert.ToDateTime(regBirth); newUser.admin = false; newUser.birth_date = birthDate; newUser.email = regEmail; newUser.name = regName; newUser.surname = regSurname; newUser.country = regCountry; try { using (var db = new HotelDBEntities()) { var checkUser = db.users.FirstOrDefault(u => u.email == regEmail); if (checkUser == null) { db.users.Add(newUser); db.SaveChanges(); info.text = "New user has been added. Now you can log in using your e-mail and password."; info.type = 1; } else { info.text = "User with this e-mail address has been alredy created."; info.type = 0; } } } catch (Exception e) { info.text = "Unexpected database error. Please contact with administrator."; info.type = 0; } } return View(info); }
public ActionResult Login(string logEmail, string logPass) { var sessioUser = (user)Session["user"]; if (sessioUser != null) { return RedirectToAction("Index", "Home"); } else { Message info = new Message(); List<bool> check = new List<bool>(); check.Add(String.IsNullOrEmpty(logEmail)); check.Add(String.IsNullOrEmpty(logPass) || logPass.Length < 6 || logPass.Length > 10); if (check.Contains(true)) { info.text = "You didn't fill correctly all of the fields. "; info.text += "Remember that: password must have between 6-10 marks."; info.type = 0; } else { try { using (var db = new HotelDBEntities()) { var checkUser = db.users.FirstOrDefault(u => u.email == logEmail); if (checkUser == null) { info.text = "You have typed wrong e-mail or password."; info.type = 0; } else { var crypto = new SimpleCrypto.PBKDF2(); var encrPass = crypto.Compute(logPass, checkUser.password_salt); if (encrPass == checkUser.password) { Session["user"] = checkUser; return RedirectToAction("Index", "Home"); } else { info.text = "You have typed wrong e-mail or password."; info.type = 0; } } } } catch (Exception e) { info.text = "Unexpected database error. Please contact with administrator."; info.type = 0; } } return RedirectToAction("Index", "Home", new { info.type, info.text }); } }
public ActionResult Book(string bookStart, string bookEnd, int bookRoom = 0) { var user = (user)Session["user"]; Message info = new Message(); if (user == null) { return RedirectToAction("Index", "Reservation"); } if (String.IsNullOrEmpty(bookStart) || String.IsNullOrEmpty(bookEnd) || bookRoom == 0) { info.text = "You have to choose room number and both dates."; return RedirectToAction("Index", "Reservation", new { info.text }); } DateTime startDate = Convert.ToDateTime(bookStart); DateTime endDate = Convert.ToDateTime(bookEnd); if (startDate >= endDate) { info.text = "Start day must be earlier ther end day."; return RedirectToAction("Index", "Reservation", new { info.text }); } List<DateTime> busyDates = new List<DateTime>(); using (var db = new HotelDBEntities()) { var reservs = db.reservations.ToList(); if (reservs.Count() == 0) { reservation res = new reservation(); res.start_date = startDate; res.end_date = endDate; res.room_id = bookRoom; res.user_id = user.id; res.days = Convert.ToInt32((endDate - startDate).TotalDays); db.reservations.Add(res); db.SaveChanges(); //---------------------------------------------------------------------------- info.type = 1; info.text = "Reservations has been added."; return RedirectToAction("Index", "Reservation", new { info.type, info.text }); } else { foreach (reservation item in reservs) { busyDates.Add(item.start_date); DateTime a = item.start_date; DateTime b = item.end_date; while (a.AddDays(1) != b) { busyDates.Add(a.AddDays(1)); a = a.AddDays(1); } } if (busyDates.Contains(startDate) || busyDates.Contains(endDate.AddDays(-1))) { info.type = 0; info.text = "Room is reserved in those days."; return RedirectToAction("Index", "Reservation", new { info.type, info.text }); } else { reservation res = new reservation(); res.start_date = startDate; res.end_date = endDate; res.room_id = bookRoom; res.user_id = user.id; res.days = Convert.ToInt32((endDate - startDate).TotalDays); db.reservations.Add(res); db.SaveChanges(); //---------------------------------------------------------------------------- info.type = 1; info.text = "Reservations has been added."; return RedirectToAction("Index", "Reservation", new { info.type, info.text }); } } } }