Example #1
0
        public async Task <IActionResult> RemoveCategory(int id)
        {
            var cateFromRepo = await _repo.GetCategoryAsync(id);

            _repo.Delete(cateFromRepo);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            throw new Exception("Delete failed");
        }
Example #2
0
        public async Task <IActionResult> DeleteUser(string uId, string aId)
        {
            var userFromRepo = await _userManager.FindByIdAsync(uId);

            var admin = await _repo.GetUserAsync(aId);

            var adminRoles = await _userManager.GetRolesAsync(admin);

            if (aId.Equals(uId) || adminRoles.Contains("Admin"))
            {
                _repo.Delete(userFromRepo);

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

            throw new Exception(userFromRepo.UserName + " unable to remove");
        }