public ActionResult Create(User user, string Password, string PasswordConfirm, FormCollection collection) { // Реп if (DataContext.Users.Any(u => u.Email.ToLower() == user.Email.ToLower())) { ShowError("Такой пользователь уже зарегистрирован"); return RedirectToAction("Index"); } // Регистрируем user.PasswordHash = PasswordUtils.GenerateMD5PasswordHash(Password); user.DateRegistred = DateTime.Now; // Устанавливаем допуски для пользователя foreach (var projectId in collection.AllKeys.Where(k => k.StartsWith("project_")).Select(key => Convert.ToInt64(key.Split('_')[1]))) { user.ProjectUsers.Add(new ProjectUser() { ProjectId = projectId, User = user, DateCreated = DateTime.Now }); } foreach (var warehouseId in collection.AllKeys.Where(k => k.StartsWith("warehouse_")).Select(key => Convert.ToInt64(key.Split('_')[1]))) { user.WarehouseKeepers.Add(new WarehouseKeeper() { WarehouseId = warehouseId, User = user, DateCreated = DateTime.Now }); } DataContext.Users.InsertOnSubmit(user); DataContext.SubmitChanges(); ShowSuccess(string.Format("Успешно зарегистрирован пользователь {0} {1}. На его почту отправлено письмо с информацией о регистрации", user.GetFio(), user.Email)); // Уведомляем var notificationModel = new { FIO = user.GetFio(), Email = user.Email, Password = Password }; NotifyEmail(user, "Регистрация в системе LeadControl", new ParametrizedFileTemplate( Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates", "Mail", "Register.html"), notificationModel).ToString()); return RedirectToAction("Index"); }