public ActionResult Add() { var streamReader = new StreamReader(_context.Request.InputStream); var jsonSerializer = new JsonSerializer(); var userModel = jsonSerializer.Deserialize <UserModel>(new JsonTextReader(streamReader)); if (_userPersistence.Add(userModel) == PersistenceCodes.IdAlreadyUsed) { return(Error()); } return(Json(userModel)); }
public void CreateUser(User user) { var pass = user.Password; try { if (String.IsNullOrEmpty(user.Name)) { throw new Exception("Error en el usuario. Debe tener Nombre"); } if (!isPasswordValid(user.Password)) { throw new Exception("La contraseña debe tener un minimo de 8 caracteres, con una Mayuscula, una minuscula y un número"); } Regex regex = new Regex(@"(\w+)@(\w+)\.(\w+)"); if (!regex.IsMatch(user.Mail)) { throw new Exception("Error en el mail"); } if (user.Age <= 0 || user.Age > 100) { throw new Exception("Error en la edad. Debes ser mayor a 0, y menor a 100"); } byte[] data = System.Text.Encoding.ASCII.GetBytes(user.Password); data = new System.Security.Cryptography.SHA256Managed().ComputeHash(data); user.Password = System.Text.Encoding.ASCII.GetString(data); } catch (Exception e) { throw new Exception(e.Message); } userPersistence.Add(user); }
public void Create(User user) => userPersistence.Add(user);