Esempio n. 1
0
        public async Task <IActionResult> GetLogin([FromQuery] string login)
        {
            if (login == "")
            {
                ErrorViewModel.IsEmptyUser();
            }
            var isLogin = await db.Users.FirstOrDefaultAsync(l => l.Login == login);

            if (isLogin != null)
            {
                ErrorViewModel.LoginNotEmpty();
            }
            return(Ok("Логин свободен."));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetUser([FromQuery] string user)
        {
            if (user == null)
            {
                return(ErrorViewModel.IsEmptyUser());
            }
            var checkUser = await GetIdentityUser(user);

            if (checkUser == null)
            {
                return(ErrorViewModel.NotFoundUser());
            }
            var resultCheck = new {
                id        = checkUser.Id,
                foundUser = checkUser.Login
            };

            return(Json(resultCheck));
        }
Esempio n. 3
0
        public async Task <IActionResult> GetUser([FromBody] UserCheckModel user)
        {
            string userNameTo = user.UserNameTo;

            if (userNameTo == "")
            {
                return(ErrorViewModel.IsEmptyUser());
            }
            var checkUser = await GetIdentityUser(userNameTo);

            if (checkUser == null)
            {
                return(ErrorViewModel.NotFoundUser());
            }
            var resultCheck = new {
                id        = checkUser.Id,
                foundUser = checkUser.Login
            };

            return(Json(resultCheck));
        }
Esempio n. 4
0
        public async Task <IActionResult> DeleteFriend([FromBody] UserDelete user)
        {
            if (user.UserFrom == null && user.UserTo == null)
            {
                ErrorViewModel.IsEmptyUser();
            }
            var objFriend = await db.Users.FirstOrDefaultAsync(n => n.Login == user.UserTo);

            // Узнает id друга которого нужно удалить
            int idFriend = objFriend.Id;
            // Выбирает удаляемого друга
            UsersRelations deleteUser = await db.UsersRelations.FirstOrDefaultAsync(u => u.ToUserId == idFriend);

            // Удаляет друга
            if (deleteUser != null)
            {
                db.UsersRelations.Remove(deleteUser);
                await db.SaveChangesAsync();

                return(Ok());
            }
            return(ErrorViewModel.RemoveError());
        }