public async Task <ActionResult> UsersGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Users item) { if (ModelState.IsValid) { try { // Insert here a code to insert the new item in your model item.Id = Guid.NewGuid().ToString(); item.UserName = item.Email.Split('@')[0]; var userResult = await UserManager.CreateAsync(item, item.Password); if (userResult.Succeeded) { } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["Model"] = item; ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.UsersRepo.Get(); return(PartialView("_UsersGridViewPartial", model)); }
public async System.Threading.Tasks.Task <ActionResult> UsersGridViewPartialUpdate( [ModelBinder(typeof(DevExpressEditorsBinder))] Models.Users item) { if (ModelState.IsValid) { try { // Insert here a code to update the item in your model item.UserName = item.Email; var user = unitOfWork.UsersRepo.Find(x => x.Id == item.Id); user.UserName = item.Email; user.Email = item.Email; if (!string.IsNullOrEmpty(item.Password)) { await UserManager.ChangePasswordAsync(user, item.Password); } if (item.Roles.Any()) { user.UserRoles.Clear(); foreach (var i in item.Roles) { user.UserRoles.Add(unitOfWork.UserRolesRepo.Find(x => x.Name == i)); } } unitOfWork.Save(); if (item.UserImage != null) { var img = System.Drawing.Image.FromStream(new MemoryStream(item.UserImage)); var p = $"~/content/images/user-images/{item.Id}"; img.Save(Server.MapPath(p)); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.UsersRepo.Get(); return(PartialView("_UsersGridViewPartial", model)); }
public Models.Users getUserByTzAndEmail(string tz, string email) { using (var context = new MichrazolEntities()) { int c = 5; // Perform data access using the context } var u = Connect.DB.Users.FirstOrDefault(x => x.Tz == tz && x.Mail == email); if (u == null) { return(null); } Models.Users user = ConvertFromEntitiesToModels.GetUsers(u); return(user); }
public ActionResult UsersGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Users item) { if (ModelState.IsValid) { try { item.Id = Guid.NewGuid().ToString(); item.UserName = item.Email; var res = UserManager.Create(item, item.Password); if (item.UserImage != null) { var img = System.Drawing.Image.FromStream(new MemoryStream(item.UserImage)); img.Save(Server.MapPath($"~/content/images/user-images/{User.Identity.GetUserId()}")); } if (res.Succeeded) { if (item.Roles.Any()) { foreach (var i in item.Roles) { UserManager.AddToRole(item.Id, i); } } unitOfWork.Save(); } // Insert here a code to insert the new item in your model } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.UsersRepo.Get(); return(PartialView("_UsersGridViewPartial", model)); }
public async Task <ActionResult> UsersGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Users item, [ModelBinder(typeof(DevExpressEditorsBinder))] List <string> roles) { if (ModelState.IsValid) { try { var user = unitOfWork.UsersRepo.Find(m => m.Id == item.Id, includeProperties: "UserRoles"); user.FirstName = item.FirstName; user.MiddleName = item.MiddleName; user.LastName = item.LastName; user.Email = item.Email; user.UserName = item.Email.Split('@')[0]; user.Position = item.Position; if (item.Password != null) { var res = await UserManager.ChangePasswordAsync(user, item.Password); if (res.Succeeded) { Debug.Write(res.Succeeded); } } user.UserRoles.Clear(); foreach (var i in roles) { user.UserRoles.Add(unitOfWork.UserRolesRepo.Find(m => m.Name == i)); } unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.UsersRepo.Get(); return(PartialView("_UsersGridViewPartial", model)); }
public ActionResult UserGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Users item) { var model = new object[0]; if (ModelState.IsValid) { try { // Insert here a code to update the item in your model } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(PartialView("_UserGridViewPartial", model)); }