Пример #1
0
 private async Task UpdateUser(User userToUpdate)
 {
     using (var db = ArangoDatabase.CreateWithSetting())
     {
         await db.UpdateByIdAsync <User>(userToUpdate.Id, userToUpdate);
     }
 }
Пример #2
0
        public async Task <ActionResult> CreateUser([FromBody] UserForm user)
        {
            if (string.IsNullOrEmpty(user.Username) || string.IsNullOrEmpty(user.Password) ||
                string.IsNullOrEmpty(user.Email))
            {
                return(BadRequest(new { message = "username, password or email are empty" }));
            }

            var db    = Database;
            var query = from u in db.Query <User>()
                        where u.Username == user.Username
                        select u;

            if (await query.FirstOrDefaultAsync() != null)
            {
                return(Conflict(new { message = $"Username {user.Username} already exists" }));
            }

            query = db.Query <User>().Where(u => u.Email == user.Email);
            if (await query.FirstOrDefaultAsync() != null)
            {
                return(Conflict(new { message = $"Email {user.Email} already exists" }));
            }

            var userToInsert = new User(user);

            userToInsert.Password = PasswordHasher.HashPassword(userToInsert, user.Password);
            if (!await EmailSender.SendEmailAsync(user.Email, "Bienvenido a MaxOrg", $@"MaxOrg es una plataforma
 que agilizará tus proyectos de sofware<br>Tu cuenta es: {user.Username}, podrás acceder a la plataforma desde 
https://maxorg.azurewebsites.net<br><h2>Esperamos que la plataforma te sea de utilidad :)</h2>"))
            {
                return(NotFound($"Email doesn't exist"));
            }

            var createdUser = await db.InsertAsync <User>(userToInsert);

            return(Created("api/users/" + createdUser.Key, new
            {
                message = "Please, go to 'api/login' to obtain a token",
                user.Username,
                user.Email
            }));
        }