public IActionResult Register(Both newUser) { User user = newUser.user; if (ModelState.IsValid) { if (dbContext.Users.Any(u => u.Email == user.Email)) { ModelState.AddModelError("user.Email", "Email is already in use!"); return(View("Home")); } else { PasswordHasher <User> Hasher = new PasswordHasher <User>(); user.Password = Hasher.HashPassword(newUser.user, user.Password); dbContext.Add(newUser.user); dbContext.SaveChanges(); HttpContext.Session.SetInt32("UserId", user.UserId); return(RedirectToAction("Index")); } } else { return(View("Home")); } }
public IActionResult Login(Both userSubmission) { LoginUser login = userSubmission.login; if (ModelState.IsValid) { var userInDb = dbContext.Users.FirstOrDefault(u => u.Email == login.Email); if (userInDb == null) { ModelState.AddModelError("login.Email", "Invalid Email/Password"); return(View("Home")); } var hasher = new PasswordHasher <LoginUser>(); var result = hasher.VerifyHashedPassword(userSubmission.login, userInDb.Password, login.Password); if (result == 0) { ModelState.AddModelError("login.Email", "Invalid Email/Password"); return(View("Home")); } HttpContext.Session.SetInt32("UserId", userInDb.UserId); return(RedirectToAction("Index")); } else { return(View("Home")); } }
public Both getVegNonMenu() { VegNonBothRestaurant v = new VegNonBothRestaurant(); Both bothMenu = (Both)v.GetMenus(); return(bothMenu); }
static void RunFacade() { HotelKeeper keeper = new HotelKeeper(); VegMenu v = keeper.getVegMenu(); NonVegMenu nv = keeper.getNonVegMenu(); Both both = keeper.getVegNonMenu(); }
//User profile render public ActionResult UserProfile(int?uid, string uname) { if (!uid.HasValue) { return(RedirectToAction("Login")); } using (Model1 db = new Model1()) { User usr = db.user.FirstOrDefault(u => u.id == uid); if (usr == null) { usr = db.user.FirstOrDefault(u => u.username == uname); if (usr == null) { return(RedirectToAction("Index")); } } List <Microblog> microblog = db.microblog.Where(u => u.uid == usr.id).OrderByDescending(x => x.time).Take(40).ToList(); List <Megablog> megablog = db.megablog.Where(u => u.uid == usr.id).OrderByDescending(x => x.time).Take(40).ToList(); if (Session["month"] == null) { int reads = 0; foreach (var i in microblog) { reads = reads + i.reads; } foreach (var i in megablog) { reads = reads + i.reads; } Session["month"] = "set"; usr.readers = reads; db.SaveChanges(); } Both obj = new Both(); obj.user = usr; obj.microblog = microblog; obj.megablog = megablog; return(View(obj)); } }
public IActionResult Form(Reservation reservation) { Both both = new Both(2, 15); reservation.Accepted = hotelLogic.addReservation(reservation.StartDate, reservation.EndDate); hotel.Bookings = hotelLogic.bookings; hotel.Size = hotelLogic.size; hotel.Days = hotelLogic.days; both.Reservation = reservation; both.Hotel = hotel; return(View("~/Views/Home/Index.cshtml", both)); }
public IActionResult Reset() { hotelLogic = new HotelLogic(); Both both = new Both(2, 15); hotel.Bookings = hotelLogic.bookings; hotel.Size = hotelLogic.size; hotel.Days = hotelLogic.days; both.Reservation = new Reservation(); both.Hotel = hotel; return(View("~/Views/Home/Index.cshtml", both)); }
public IActionResult Success() { int?UserId = HttpContext.Session.GetInt32("UserId"); if (HttpContext.Session.GetInt32("UserId") != null) { User retrievedUser = dbContext.Users .Include(u => u.Transactions) .FirstOrDefault(u => u.UserId == UserId); Both both = new Both(); both.user = retrievedUser; return(View("account", both)); } else { return(RedirectToAction("Index")); } }
public IActionResult Account(Transaction form) { User user = dbContext.Users .Include(data => data.Transactions) .FirstOrDefault(users => users.UserId == HttpContext.Session.GetInt32("UserId")); int AccountBalance = (int)user.Transactions.Sum(trans => trans.Amount); if (ModelState.IsValid) { if (AccountBalance + form.Amount < 0) { ModelState.AddModelError("Amount", "You may not overdraw from your account"); User retrievedUser = dbContext.Users .Include(u => u.Transactions) .FirstOrDefault(u => u.UserId == (int)HttpContext.Session.GetInt32("UserId")); Both both = new Both(); both.user = retrievedUser; return(View("account", both)); } else { Transaction Debit = new Transaction() { Amount = form.Amount, UserId = (int)HttpContext.Session.GetInt32("UserId") }; dbContext.transactions.Add(Debit); dbContext.SaveChanges(); return(RedirectToAction("Success")); } } else { return(View("account")); } }
public int GetHashCode(Both <TItem, TItem> obj) => HashCode.Combine( _itemComparer.GetHashCode(obj.Left), _itemComparer.GetHashCode(obj.Right));
public bool Equals(Both <TItem, TItem> x, Both <TItem, TItem> y) => _itemComparer.Equals(x.Left, y.Left) && _itemComparer.Equals(x.Right, y.Right);
public Menus GetMenus() { Both b = new Both(); return(b); }
/// <summary> /// Tests if the value contained in this instance is equal to the one in the other instance /// </summary> /// <param name="other">The instance to compare to</param> /// <returns>true if both instances wraps the same value, according to object.Equals rules</returns> public bool Equals(Both other) { return(object.Equals(other.LeftValue, this.LeftValue) && object.Equals(other.RightValue, this.RightValue)); }