public ActionResult ChangeSpreadsheetAdmin(AddRedactorModel model) { var userId = UserHelper.GetUserByEmail(User.Identity.Name).Id; if (ModelState.IsValid && IsUserAdmin(userId, model.SpreadsheetId)) { var adminId = userRepository.Find(w => w.Email.Equals(model.RedactorEmail)).Id; if (adminId != null) { var spreadsheet = spreadsheetRepository.Find(w => w.Id == model.SpreadsheetId); if (spreadsheet != null) { spreadsheet.AdministratorId_Id = adminId; spreadsheetRepository.Commit(); } var oldRedactor = redactorRepository.Find(w => w.UserId_Id.Equals(adminId)); var newRedactor = new TableRedactorModels { TableId = model.SpreadsheetId, UserId_Id = userId }; redactorRepository.Add(newRedactor); redactorRepository.Delete(oldRedactor); redactorRepository.Commit(); } } return RedirectToAction("ManageSpreadsheets"); }
public int RedactorAdd(long SpreadsheetId, string[] EmailsOfRedactors, string[] ListRedactorsToDelete) { if (ModelState.IsValid) { var userId = UserHelper.GetUserByEmail(User.Identity.Name).Id; if (IsUserAdmin(userId, SpreadsheetId)) { if (EmailsOfRedactors != null) { foreach (var redactorEmail in EmailsOfRedactors) { var redactorId = userRepository.Find(w => w.Email.Equals(redactorEmail)).Id; var redactorIsExist = redactorRepository.Find(r => r.UserId_Id == redactorId && r.TableId == SpreadsheetId); if (redactorId != null && redactorIsExist == null) { var redactor = new TableRedactorModels { TableId = SpreadsheetId, UserId_Id = redactorId, Administrator_Id = userId }; redactorRepository.Add(redactor); redactorRepository.Commit(); } } } if (ListRedactorsToDelete != null) { foreach (var redactorEmail in ListRedactorsToDelete) { var redactorId = userRepository.Find(w => w.Email.Equals(redactorEmail)).Id; var redactorIsExist = redactorRepository.Find(r => r.UserId_Id == redactorId && r.TableId == SpreadsheetId); if (redactorId != null && redactorIsExist != null) { redactorRepository.Delete(redactorIsExist); redactorRepository.Commit(); } } } } } return 0; }
public async Task<ActionResult> RegisterByInvite(RegisterByInviteViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { // если создание прошло успешно, то добавляем роль пользователя await UserManager.AddToRoleAsync(user.Id, UserRoles.Redactors.ToString()); await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // Дополнительные сведения о том, как включить подтверждение учетной записи и сброс пароля, см. по адресу: http://go.microsoft.com/fwlink/?LinkID=320771 // Отправка сообщения электронной почты с этой ссылкой // 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, "Подтверждение учетной записи", "Подтвердите вашу учетную запись, щелкнув <a href=\"" + callbackUrl + "\">здесь</a>"); Repository<AspNetUsers> userRepository = new Repository<AspNetUsers>(); var newUser = userRepository.Find(w => w.Email.Equals(model.Email)); if (newUser != null && newUser.CloudmailinEmail == null) { newUser.CloudmailinEmail = string.Format(Constants.PathConstants.Email, newUser.Email.Replace("@", "at")); if (newUser.Units == 0) { newUser.Units = 1; } userRepository.Commit(); if (model.adminEmail != null) { var admin = userRepository.Find(a => a.Email == SendMailHelper.Decrypt(model.adminEmail)); var redactor = new Model.TableRedactorModels() { Administrator_Id = admin.Id, TableId = -1, UserId_Id = newUser.Id }; redactorsRepository.Commit(); } } return RedirectToAction("Index", "Home"); } AddErrors(result); } // Появление этого сообщения означает наличие ошибки; повторное отображение формы return View(model); }
partial void DeleteTableRedactorModels(TableRedactorModels instance);
partial void UpdateTableRedactorModels(TableRedactorModels instance);
partial void InsertTableRedactorModels(TableRedactorModels instance);
private void detach_TableRedactorModels(TableRedactorModels entity) { this.SendPropertyChanging(); entity.AspNetUsers = null; }