public ActionResult EditOptionalDatas(ManageViewModel m) { var db = HttpContext.GetOwinContext().Get <ApplicationDbContext>(); var userId = User.Identity.GetUserId(); if (ModelState.IsValid) { try { Cathedral c = db.Cathedrals.FirstOrDefault(x => x.Department == m.CathedralName); UserManager.FindById(userId).CathedralID = c; UserManager.FindById(userId).Description = m.Description; UserManager.FindById(userId).DateOfBirth = m.DateOfBirth; UserManager.FindById(userId).Photo = m.Photo; var dbToChange = db.Users.Find(userId); db.Entry(db.Users.Find(userId)).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (RetryLimitExceededException) { ModelState.AddModelError("", "Niemożliwa była zmiana danych."); } } m.Cathedrals = db.Cathedrals.ToList(); return(View(m)); }
public async Task <ActionResult> UnlockUsers(ManageUsersModel model) { ApplicationUser currentUser = db.Users.Find(User.Identity.GetUserId()); if (currentUser.AdminID != null) { if (ModelState.IsValid) { var db = HttpContext.GetOwinContext().Get <ApplicationDbContext>(); var user = UserManager.FindById(model.Id); Cathedral c = db.Cathedrals.FirstOrDefault(x => x.Department == model.CathedralName); user.CathedralID = c; user.LockoutEnabled = false; var result = await UserManager.UpdateAsync(user); db.SaveChanges(); // If we got this far, something failed, redisplay form } return(View(model)); } else { return(RedirectToAction("../Home/Index")); } }
public ActionResult DeleteConfirmed(int id) { Cathedral cathedral = db.Cathedrals.Find(id); db.Cathedrals.Remove(cathedral); db.SaveChanges(); return(RedirectToAction("Index")); }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (_allCathedrals.Count(x => x.Name == _selectedCathedral.Name) == 0 && !string.IsNullOrEmpty(_selectedCathedral.Name) && _selectedCathedral.Max > 0) { _selectedCathedral.Id = 0; _repo.InsertItem <Cathedral>(_selectedCathedral); GetAllCathedrals(); _selectedCathedral = new Cathedral(); } }
public ActionResult Edit([Bind(Include = "ID,Department,Address,Page,PhoneNumber,Email")] Cathedral cathedral) { if (ModelState.IsValid) { db.Entry(cathedral).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cathedral)); }
public ActionResult Create([Bind(Include = "ID,Department,Address,Page,PhoneNumber,Email")] Cathedral cathedral) { if (ModelState.IsValid) { db.Cathedrals.Add(cathedral); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cathedral)); }
// GET: Cathedrals/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Cathedral cathedral = db.Cathedrals.Find(id); if (cathedral == null) { return(HttpNotFound()); } return(View(cathedral)); }
public async Task <ActionResult> ManageUsers(ManageUsersModel model) { if (ModelState.IsValid) { var db = HttpContext.GetOwinContext().Get <ApplicationDbContext>(); var user = UserManager.FindById(model.Id); Cathedral c = db.Cathedrals.FirstOrDefault(x => x.Department == model.CathedralName); if (user.AdminID != null) { model.isAdmin = true; } else { model.isAdmin = false; } user.FirstName = model.FirstName; user.LastName = model.LastName; user.Email = model.Email; user.CathedralID = c; //Działa przy debugowaniu krok po kroku, ale tak normalnie to nie działa?!? if (model.isAdmin == true) { Admin op = new Admin(); int val = 0; Int32.TryParse(user.Id, out val); op.ID = val; user.AdminID = op; } else { user.AdminID = null; } // db.Entry(user).State = EntityState.Modified; var result = await UserManager.UpdateAsync(user); db.SaveChanges(); // If we got this far, something failed, redisplay form } return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var db = HttpContext.GetOwinContext().Get <ApplicationDbContext>(); Cathedral c = db.Cathedrals.FirstOrDefault(x => x.Department == model.CathedralName); NormalUser nu = db.NormalUsers.FirstOrDefault(x => x.ID == 1); if (nu == null) { var normalUser = new NormalUser { ID = 1 }; db.NormalUsers.Add(normalUser); db.SaveChanges(); nu = db.NormalUsers.FirstOrDefault(x => x.ID == 1); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FisrtName, LastName = model.LastName, CathedralID = c, UserConfirmed = false, LockoutEnabled = false, NormalUserID = nu }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> ConfirmUsers(ManageUsersModel model) { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated == true) { if (ModelState.IsValid) { var db = HttpContext.GetOwinContext().Get <ApplicationDbContext>(); var user = UserManager.FindById(model.Id); Cathedral c = db.Cathedrals.FirstOrDefault(x => x.Department == model.CathedralName); user.CathedralID = c; user.UserConfirmed = true; var result = await UserManager.UpdateAsync(user); db.SaveChanges(); // If we got this far, something failed, redisplay form } return(View(model)); } else { return(RedirectToAction("../Home/Index")); } }
private void lsvCathedral_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { _selectedCathedral = lsvCathedral.SelectedValue as Cathedral; DataContext = _selectedCathedral; }