Ejemplo n.º 1
0
        public async Task <IActionResult> DeletePassword(int id)
        {
            // getting the user id
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var passwordsUser = await _repo.GetPasswords(currentUserId);

            if (!passwordsUser.Any(x => x.Id == id))
            {
                return(Unauthorized());
            }

            var ok = await _repo.DeletePassword(id);

            if (!ok)
            {
                return(BadRequest("The password you want to delete does not exists"));
            }

            if (await _repo.SaveAll())
            {
                return(StatusCode(204));
            }

            return(BadRequest("Cannot delete password."));
        }
Ejemplo n.º 2
0
        public async Task DeletePassword()
        {
            if (appController.Busy)
            {
                return;
            }
            else
            {
                appController.EnableBusyState();
            }

            var vm = viewModelsController.GetViewModel <DeleteViewModel>();

            if (vm.SelectedPassword == null)
            {
                appController.DisableBusyState();
                return;
            }

            try
            {
                await appRepository.DeletePassword(vm.SelectedPassword.Id);

                appController.RefreshViewModels();

                appController.DisableBusyState();
                appController.ShowInfoPage("Success!", "Password Deleted!");
            }
            catch (Exception)
            {
                appController.DisableBusyState();
                appController.ShowInfoPage("Issue!", "Please try again!");
            }
        }