Example #1
0
        public async Task <ApiResult> Delete([FromUri] string id, CancellationToken cancelToken)
        {
            if (Authorization == null)
            {
                return(new ApiResult(APIResultCode.Unknown, APIResultMessage.TokenNull));
            }

            if (string.IsNullOrWhiteSpace(id))
            {
                throw new NotImplementedException("业主Id信息为空!");
            }

            var user = _tokenRepository.GetUser(Authorization);

            if (user == null)
            {
                return(new ApiResult(APIResultCode.Unknown, APIResultMessage.TokenError));
            }

            await _ownerRepository.DeleteAsync(new OwnerDto
            {
                Id              = id,
                OperationTime   = DateTimeOffset.Now,
                OperationUserId = user.Id.ToString()
            }, cancelToken);

            return(new ApiResult());
        }
Example #2
0
        /// <summary>
        /// delete the user owner
        /// </summary>
        /// <param name="id">user id</param>
        /// <returns>view index</returns>
        // POST: Owners/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new NotFoundViewResult("OwnerNotFound"));
            }

            var owner = await _ownerRepository.GetByIdAsync(id.Value);

            if (owner == null)
            {
                return(new NotFoundViewResult("OwnerNotFound"));
            }

            if (owner.Pets.Count > 0)
            {
                return(RedirectToAction(nameof(Index)));
            }

            try
            {
                await _ownerRepository.DeleteAsync(owner);
            }
            catch (Exception exception)
            {
                ModelState.AddModelError(string.Empty, exception.Message);
            }


            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var owner = await _ownerRepository.FindByIdAsync(id);

            await _ownerRepository.DeleteAsync(owner);

            return(RedirectToAction(nameof(Index)));
        }
Example #4
0
        public async Task DeleteAsync(string ownersLogin)
        {
            var ownerToDelete = await _ownerRepository.GetAsync(ownersLogin);

            if (ownerToDelete == null)
            {
                throw new ServiceException(ErrorCodes.OwnerNotFound, "Owner doesn't exist.");
            }

            await _ownerRepository.DeleteAsync(ownersLogin);
        }
Example #5
0
 public async Task DeleteAsync(int id)
 {
     await _ownerRepository.DeleteAsync(id);
 }