public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var lib = new UserLib(); var result = lib.Login(model.UserName, Encryptor.MD5Hash(model.Password)); if (result == 1) { var user = lib.GetById(model.UserName); var userSession = new UserLogin(); userSession.UserName = user.UserName; userSession.UserID = user.ID; Session.Add(CommonConstants.USER_SESSION, userSession); return(Redirect("/")); } else if (result == 0) { ModelState.AddModelError("", "Tài khoản không tồn tại."); } else if (result == -1) { ModelState.AddModelError("", "Tài khoản đang bị khoá."); } else if (result == -2) { ModelState.AddModelError("", "Mật khẩu không đúng."); } else { ModelState.AddModelError("", "đăng nhập không đúng."); } } return(View(model)); }
public static void Check() { bool isSafe = true; int pressure; UserLib.WriteTitle("Pressure Check"); while (isSafe) { pressure = UserLib.GetInt("Enter Pressure > "); if (pressure < LOW_PRESSURE) { Console.WriteLine("Pressure is too low!"); } else if ((pressure >= LOW_PRESSURE) && (pressure <= HIGH_PRESSURE)) { Console.WriteLine("Pressure is Normal!"); } else if ((pressure > HIGH_PRESSURE) && (pressure < DANGEROUS_PRESSURE)) { Console.WriteLine("Pressure is too high!"); } else if (pressure >= DANGEROUS_PRESSURE) { Console.WriteLine("Pressure is DANGEROUS!"); isSafe = false; } } Console.WriteLine("Shut Down!!!"); }
/// <summary> /// This method will ask the user to enter the number of feet /// and it will convert that value to miles and display the /// result to the user /// </summary> public static void TestFeetToMiles() { UserLib.WriteTitle("Task 4.1 Feet -> Miles"); feet = UserLib.GetDouble("Please enter the number of feet > "); miles = DistanceConverter.FeetToMiles(feet); Console.WriteLine("The number of miles = " + miles.ToString("#.##")); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { var lib = new UserLib(); if (!string.IsNullOrEmpty(user.Password)) { var encryptedMd5Pas = Encryptor.MD5Hash(user.Password); user.Password = encryptedMd5Pas; } var result = lib.Update(user); if (result) { SetAlert("Edit user successfully ", "success"); return(RedirectToAction("Index", "User")); } else { ModelState.AddModelError("", "Update user not successfully"); } } return(View("Index")); }
/// <summary> /// This method will ask the user to enter the number of miles /// and it will convert that value to feet and display the /// result to the user /// </summary> public static void TestMilesToFeet() { UserLib.WriteTitle("Task 4.1 Miles -> Feet"); miles = UserLib.GetDouble("Please enter the number of miles > "); feet = DistanceConverter.MilesToFeet(miles); Console.WriteLine("The number of feet = " + feet.ToString("#.##")); }
public static void Load() { double weight = 0; double totalWeight = 0; int count = 0; decimal moneyTaken = 0; bool isFull = false; UserLib.WriteTitle("Passenger Ferry"); while (!isFull) { count++; weight = UserLib.GetDouble("Enter next passenger weight > "); if (totalWeight + weight > MAX_WEIGHT) { Console.WriteLine("Max weight exceeded!"); Console.WriteLine("Passenger Rejected!"); isFull = true; count--; } else { Console.WriteLine("Passenger Accepted!"); moneyTaken += 100; totalWeight += weight; } } Console.WriteLine("Total Money = " + moneyTaken.ToString("c")); Console.WriteLine("Number of Passenger = " + count); Console.WriteLine("Total Weight = " + totalWeight.ToString("####")); }
public static void Play() { bool won = false; bool lost = false; int diceNo1; int diceNo2; int total; UserLib.WriteTitle("Craps Game"); while (!won && !lost) { diceNo1 = Dice.Throw(); diceNo2 = Dice.Throw(); total = diceNo2 + diceNo1; Console.WriteLine("Total = " + total); Console.ReadKey(); if ((total == 2) || (total == 3) || (total == 12)) { lost = true; Console.WriteLine("You have lost!!!"); } } }
public void RunSimulator() { bool displayField = false; UserLib.OutputHeading(" Foxes and Rabbits Sumulation"); int lastStep = (int)UserLib.InputNumber("Run the simulation how many times > "); Console.WriteLine(); Console.Write(" Do you want to display the field (Y/N) >"); string answer = Console.ReadLine(); if (answer.ToLower() == "y") { displayField = true; } for (int step = 1; step <= lastStep; step++) { simulator.SimulateOneStep(); if (displayField) { Console.WriteLine(simulator.Field.ToString()); } CountAnimals(); string result = stats.GetPopulationDetails(simulator.Field); Console.WriteLine(result); } }
/// <summary> /// ******************************************************* /// This method will End the Game with the overall Winner's name /// ******************************************************* /// </summary> private static void EndGame() { Console.Clear(); UserLib.WriteTitle(Title); Console.WriteLine("The overall winner is " + Game.Winner); }
public static void BuyWeapons() { decimal money; decimal price; int count = 0; decimal total = 0; decimal moneyLeft = 0; UserLib.WriteTitle("Game Store"); money = UserLib.GetDecimal("Enter the amount of money you have to spend > "); for (count = 1; count <= 6; count++) { price = UserLib.GetDecimal("Enter the price of item " + count + " > "); total += price; moneyLeft = money - total; Console.WriteLine("Money Left = " + moneyLeft.ToString("c")); } Console.WriteLine(); Console.WriteLine("You have bought " + count + " weapons"); Console.WriteLine("Total Cost = " + total.ToString("c")); Console.WriteLine("Money Left = " + moneyLeft.ToString("c")); }
public static void ShowName() { int x = 2, y = 10; ConsoleColor colour; String[] colorNames = ConsoleColor.GetNames(typeof(ConsoleColor)); string name; int count = 0; name = "Derek"; while (count < 10) { y = y + 1; UserLib.WriteTitle("Show Name"); Console.SetCursorPosition(x, y); Console.Write(name); Thread.Sleep(500); Console.Clear(); Console.BackgroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), colorNames[count]); count++; } }
// GET: Admin/User public ActionResult Index(string searchString, int page = 1, int pageSize = 3) { var lib = new UserLib(); var model = lib.ListAllPaging(searchString, page, pageSize); ViewBag.SearchString = searchString; return(View(model)); }
/// <summary> /// Input the users height in metres and /// their weight in kilograms /// </summary> private void InputMetricDetails() { metres = UserLib.InputNumber( " \n Enter your height in metres > "); kilograms = UserLib.InputNumber( " Enter your weight in kilograms > "); }
/// <summary> /// This method will ask the user to enter the number of miles /// and it will convert that value to feet and display the /// result to the user /// </summary> public void TestMilesToFeet() { UserLib.WriteTitle("Task 4.1 Miles -> Feet"); miles = UserLib.GetDouble("Please enter the number of miles > "); feet = converter.MilesToFeet(miles); Console.WriteLine("The number of feet = " + feet); }
public void InputValues() { UserLib.WriteTitle("Game Score"); player = UserLib.GetString("Your name > "); aliens = UserLib.GetInt("How many aliens have you killed > "); treasure = UserLib.GetInt("How much treasure have you found > "); hours = UserLib.GetInt("How many hours did you play > "); }
public void WriteChapter(int chapter) { UserLib.WriteTitle("Task 4.2 " + Title); Console.WriteLine("As I slowly opened the back door, I saw a \n" + Weapon + " lying on the floor. I called out \n" + Name + "'s name and followed the blood trail into \n" + "the next room. In the darkness I saw \n" + Name + " lying at a very sinister angle."); }
//This method is to get the player's details public void GetDetails() { for (int i = 0; i < MAXN_SCORES; i++) { names[i] = UserLib.GetString("Player name > "); Console.Write("Enter score " + (i + 1) + " > "); scores[i] = Convert.ToInt32(Console.ReadLine()); } }
public JsonResult ChangeStatus(long id) { var result = new UserLib().ChangeStatus(id); return(Json(new { status = result })); }
/// <summary> /// This is the main method that can be used to run an instance /// of this Tournament class /// </summary> public static void Main() { UserLib.WriteTitle("5.1 Tournament Scores"); Tournament myTournament = new Tournament(); myTournament.GetDetails(); myTournament.ShowDetails(); myTournament.ShowBest(); Console.ReadKey(); }
public bool CheckUser(UserLib user) { // if there are no users with the provided first and last name if (_db.Users.Where(u => u.FirstName == user.FirstName && u.LastName == user.LastName).ToList().Count == 0) { return(false); } else { return(true); // if there is a match } }
//This method shows how many votes each song has public void Show() { Console.Clear(); UserLib.WriteTitle("Top Ten MP3"); int i = 0; foreach (string song in songs) { i++; Console.WriteLine("\tSong No " + i + " has " + " < " + votes[i - 1] + " > " + " votes " + song); //Console.WriteLine("\tTotal number of votes " + " < " + votes[i] + " > "); } }
/// <summary> /// ******************************************************* /// This method will Get the Player's Choice /// ******************************************************* /// </summary> private static void GetPlayerChoice() { Console.Clear(); UserLib.WriteTitle(Title); Console.WriteLine("Turn no " + turn + " of " + MAXN_TURNS); string[] choices = new string[] { Game.SCISSORS, Game.PAPER, Game.STONE }; int choiceNo = UserLib.GetChoice(choices); Game.PlayerChoice = choices[choiceNo - 1]; Console.WriteLine(); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { var lib = new UserLib(); if (lib.CheckUserName(model.UserName)) { ModelState.AddModelError("", "The account has existed !"); } else if (lib.CheckEmail(model.Email)) { ModelState.AddModelError("", "Email has existed"); } else { var user = new User(); user.UserName = model.UserName; user.Name = model.Name; user.Password = Encryptor.MD5Hash(model.Password); user.Phone = model.Phone; user.Email = model.Email; user.Address = model.Address; user.CreatedDate = DateTime.Now; user.Status = true; if (!string.IsNullOrEmpty(model.ProvinceID)) { user.ProvinceID = int.Parse(model.ProvinceID); } if (!string.IsNullOrEmpty(model.DistrictID)) { user.DistrictID = int.Parse(model.DistrictID); } var result = lib.Insert(user); if (result > 0) { ViewBag.Success = "Register Successfully"; model = new RegisterModel(); } else { ModelState.AddModelError("", "Register Unsuccessfully."); } } } return(View(model)); }
// POST public IActionResult Login(Users users) { UserLib user = new UserLib(0, users.FirstName, users.LastName); var s = Repo.CheckUser(user); if (s) { Console.WriteLine("or is this being run"); return(View("UserLandingView")); } else { Console.WriteLine("is this being run"); return(View(_context.Users.ToListAsync())); } }
/// <summary> /// List a one line summary of all the posts and /// allow the user to select one by position in /// the list. First position = 1 /// </summary> public Post SelectPost() { string[] choices = new string[Posts.Count]; int i = 0; foreach (Post post in Posts) { choices[i] = post.GetSummary(); i++; } Console.WriteLine("\n Listing of all Posts"); int choiceNo = UserLib.SelectChoice(choices); return(Posts[choiceNo - 1]); }
///<summary> /// Prompt the user to select Imperial or Metric /// units. Input the user's height and weight and /// then calculate their BMI value. Output which /// weight category they fall into. ///</summary> public void CalculateIndex() { UserLib.OutputHeading("\tBMI Calculator"); UnitSystem unitSystem = SelectUnits(); if (unitSystem == UnitSystem.Metric) { InputMetricDetails(); index = kilograms / (metres * metres); } else { InputImperialDetails(); index = pounds * 703 / (inches * inches); } OutputHealthMessage(); }
///<summary> /// Prompt the user to select Imperial or Metric /// units. Input the user's height and weight and /// then calculate their BMI value. Output which /// weight category they fall into. ///</summary> public void CalculateIndex() { UserLib.OutputHeading("\tBMI Calculator"); UnitSystem unitSystem = SelectUnits(); if (unitSystem == UnitSystem.Metric) { InputMetricDetails(); CalculateMetricBMI(); } else { InputImperialDetails(); CalculateImperialBMI(); } OutputHealthMessage(); }
/// <summary> /// Prompt the user to select imperial or metric /// units for entering their weight and height /// </summary> private UnitSystem SelectUnits() { string[] choices = new[] { "Metric Units", "Imperial Units" }; int choice = UserLib.SelectChoice(choices); if (choice == 1) { return(UnitSystem.Metric); } else { return(UnitSystem.Imperial); } }
/// <summary> /// Display a menu of distance units and then prompt the /// user to select one and return it. /// </summary> private DistanceUnit SelectUnit(string prompt) { Console.WriteLine(prompt); string[] choices = { $" {DistanceUnit.Feet}", $" {DistanceUnit.Metres}", $" {DistanceUnit.Miles}" }; int choice = UserLib.SelectChoice(choices); DistanceUnit unit; if (choice == 1) { unit = DistanceUnit.Feet; } else if (choice == 2) { unit = DistanceUnit.Metres; } else { unit = DistanceUnit.Miles; } Console.WriteLine($" You have selected {unit}"); Console.WriteLine(); // Alternative to the if..else //switch (choice) //{ // case "1": unit = DistanceUnit.Feet; break; // case "2": unit = DistanceUnit.Metres; break; // case "3": unit = DistanceUnit.Miles; break; // default: unit = "INVALID CHOICE"; break; //} return(unit); }
public ActionResult Create(User user) { if (ModelState.IsValid) { var lib = new UserLib(); var encryptedMd5Pas = Encryptor.MD5Hash(user.Password); user.Password = encryptedMd5Pas; long id = lib.Insert(user); if (id > 0) { SetAlert("Add user successfully ", "success"); return(RedirectToAction("Index", "User")); } else { ModelState.AddModelError("", "Add user successfully"); } } return(View("Index")); }