Ejemplo n.º 1
0
		public ActionResult ResetSecurityAdministratorPassword(FormCollection collection)
		{
			try
			{
				var model = new SecurityAdminsModel();
				UpdateModel(model);

				//AspNetSecurityModel
				using (var db = new ParkingPermitContext())
				{
					//db.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

					var hasher = new PasswordHasher();

					var securityAdmin = db.AspNetUsers.FirstOrDefault(u => u.Id == model.Id);

					if (securityAdmin == null) return RedirectToAction("Index");

					securityAdmin.PasswordHash = hasher.HashPassword("Password.1");
					db.AspNetUsers.AddOrUpdate(securityAdmin);
					db.SaveChanges();
				}


				return RedirectToAction("Index");
			}
			catch
			{
				return View();
			}
		}
		public ActionResult ChangePassword(FormCollection collection)
		{
			try
			{
				var model = new SecurityAdminsModel();
				UpdateModel(model);

				//AspNetSecurityModel
				using (var db = new ParkingPermitContext())
				{
					//db.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

					var hasher = new PasswordHasher();

					var securityAdmin = db.AspNetUsers.FirstOrDefault(u => u.UserName == model.UserName);

					if (securityAdmin == null) return RedirectToAction("Index");

					securityAdmin.PasswordHash = hasher.HashPassword(model.Password);
					db.AspNetUsers.AddOrUpdate(securityAdmin);
					db.SaveChanges();
				}

				return RedirectToAction("Index");
			}
			catch (Exception ex)
			{
				// ReSharper disable once UnusedVariable
				var msg = ex.Message;
				return View();
			}
		}
Ejemplo n.º 3
0
		public ActionResult DeleteSecurityAdministrator(string id,FormCollection collection)
		{
			try
			{
				//var model = new SecurityAdminsModel();
				//UpdateModel(model);

				// AspNetSecurityModel
				using (var db = new ParkingPermitContext())
				{
					db.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

					//Commented out for debugging
					var securityAdmin = db.AspNetUsers.FirstOrDefault(u => u.Id == id);
					db.AspNetUsers.Remove(securityAdmin);
					db.SaveChanges();
				}


				return RedirectToAction("Index");
			}
			catch
			{
				return View();
			}
		}