public ModelViewUser Insert(ModelViewUser model) { var objRepository = new RepositoryUser(); var objSecurity = new BusinessSecurity(); bool salir = false; string token = ""; while (!salir) { token = objSecurity.GenerateToken(); if (objRepository.GetToken(token) == null) { salir = true; } } string clave = objSecurity.GeneratePassword(8); if (objRepository.GetEmail(model.Email) != null) { throw new Exception("DuplicateEmail"); } if (objRepository.GetUserName(model.UserName) != null) { throw new Exception("DuplicateUser"); } EntityUser data = new EntityUser() { UserID = model.UserID, ProfileID = model.ProfileID, UserName = model.UserName, Name = model.Name, Password = new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(clave), Token = token, ChangePassword = true, Email = model.Email, Status = true, DateLastAccess = DateTime.UtcNow, DateCreate = DateTime.UtcNow, DateModification = DateTime.UtcNow }; data = objRepository.Insert(data); model.UserID = data.UserID; List <string> arr = new List <string>(); arr.Add(model.Email); string sb = File.ReadAllText(GlobalConfiguration.LocateBodyMail + "NotificationUserBodyContent.txt"); sb = sb.Replace("#%NombreUsuario%#", data.UserName); sb = sb.Replace("#%ClaveTemporal%#", clave); sb = sb.Replace("#%Nombre%#", data.Name); //Nombre de usuario, usuario, pass, //new BusinessNotification().SendMails(arr, "Mabe - Registro de usuario ServiPlus", sb); new BusinessNotification().SendMailExchange(GlobalConfiguration.exchangeUser, GlobalConfiguration.exchangePwd, arr, "Mabe - Registro de usuario ServiPlus", sb); return(model); }