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.º 2
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();
			}
		}
Ejemplo n.º 3
0
		public ActionResult DeleteSecurityAdministrator(string id)
		{
			// AspNetSecurityModel
			using (var db = new ParkingPermitContext())
			{
				var securityAdmin = db.AspNetUsers.FirstOrDefault(u => u.Id == id);

				if (securityAdmin != null)
				{
					var model = new SecurityAdminsModel
					{
						Id = securityAdmin.Id,
						UserName = securityAdmin.UserName
					};

					return View(model);
				}
			}

			return View();
		}
Ejemplo n.º 4
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();
			}
		}
Ejemplo n.º 5
0
		public ActionResult ShowSecurityAdministrators()
		{
			var models = new List<SecurityAdminsModel>();

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

				var securityAdmins = db.AspNetUsers
					.Where(u => u.AspNetRoles.Any(r => r.Name == "securityadmin"))
					.ToList();


				models.AddRange(securityAdmins.Select(admin => new SecurityAdminsModel {Id = admin.Id, UserName = admin.UserName}));
			}


			return View(models);
		}