Esempio n. 1
0
        public async Task <IActionResult> DeleteUser(int id, [FromBody] UserLoginDto user)
        {
            bool ok = await _repo.DeleteUser(id, user.Password);

            if (!ok)
            {
                return(BadRequest("Password doesn't match"));
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Cannot delete user."));
        }
        /// <summary>
        /// حذف کاربر
        /// </summary>
        /// <param name="id"></param>
        public void DeleteUser(Guid id)
        {
            var user = _repository.FindUser(id).Result;

            if (user == null)
            {
                throw new CustomException("کاربر مورد نظر یافت نشد");
            }
            var identityResult = _repository.DeleteUser(user).Result;

            if (!identityResult.Succeeded)
            {
                throw new CustomException(identityResult.Errors.Aggregate("",
                                                                          (current, error) => current + error + "\n"));
            }
        }
        public ActionResult Delete(int id)
        {
            _dataRepository.DeleteUser(id);

            return(RedirectToAction("List"));
        }