public ActionResult teacherLogin(Teacher teacher) { //check if the username and password matches Teacher current = m.Teachers.First((t) => t.Username == teacher.Username && t.Password == teacher.Password); if (current != null) { //new instance of the Activity class Activity teacherActivity = new Activity(); //assigns the teacher's name as the username teacherActivity.ActivityName = "Username: "******"Teacher", current.Username); return(Redirect("/")); } else { //error handling ViewBag["error"] = "Login failed. Could not find a teacher with that username and password"; return(View("TeacherLogin")); } }
public IEnumerable <Calculation> Delete()//return empty IEnumerable { using (var context = new MathDbContext()) { context.Calculations.RemoveRange(context.Calculations.ToList()); context.SaveChanges(); return(context.Calculations.ToArray()); } }
public CalcApiResult Post(string operationName, [FromBody] InputNumbers numbers) { Operation op; switch (operationName.ToLower()) { case "osszeadas": op = Operation.összeadás; break; case "kivonas": op = Operation.kivonás; break; case "szorzas": op = Operation.szorzás; break; case "osztas": op = Operation.osztás; if (numbers.BNum == 0) { throw new DivideByZeroException("Nullával való osztás nem értelmezhető! A számítás nem került rögzítésre."); } break; case "hatvanyozas": op = Operation.hatványozás; break; default: throw new Exception("Nem definiált művelet! Csak az osszeadas, kivonas, szorzas, osztas illetve hatvanyozas műveleti kulcsszó használata elfogadott(ékezett nélkül)!" + " api/math/<művelet>"); } CalcApiResult calcApi; /// Calculate and save result into database using (var context = new MathDbContext()) { calcApi = new CalcApiResult ( anum: numbers.ANum, bnum: numbers.BNum, muvelet: op.ToString(), eredmeny: numbers.CalculateOperation(op.ToString()) ); Calculation calculation = new () { Created = DateTime.Now, Anum = calcApi.ANum, Bnum = calcApi.BNum, Muvelet = calcApi.Muvelet, Eredmeny = calcApi.Eredmeny }; context.Calculations.Add(calculation); context.SaveChanges(); } return(calcApi); } }