public IHttpActionResult DeleteUserReceipt(string userName, int receiptId)
        {
            if (!ModelState.IsValid)
            {
                var message = responseService.ModelStateErrorsToString(ModelState);
                return(BadRequest(message));
            }

            string tokenName = this.authService.GetUserName(this.User);

            if (!tokenName.Equals(userName))
            {
                return(Unauthorized());
            }

            string userId = this.authService.GetUserId(this.User);

            try
            {
                repository.Delete(userId, receiptId);
            }
            catch (Exception)
            {
                return(BadRequest("Receipt was not deleted."));
            }

            return(Ok());
        }
示例#2
0
        public void Delete(Guid id)
        {
            var entity = receiptRepository.GetById(id);

            receiptRepository.Delete(entity);
            receiptRepository.SaveChanges();
        }
示例#3
0
        public IActionResult Delete(int Id)
        {
            var delete = _receiptRepository.Delete(Id);

            if (delete > 0)
            {
                return(Ok(delete));
            }
            return(BadRequest("Can't be deleted"));
        }
        public IActionResult Delete(int id)
        {
            try
            {
                var receipt = _repo.Get(id);

                if (receipt != null)
                {
                    _repo.Delete(id);
                    return(NoContent());
                }

                return(NotFound());
            }
            catch
            {
                return(ReturnUserFriendlyError(Errors.Unknown));
            }
        }
示例#5
0
        public XHRResponse <bool> Delete(string userId, int receiptId)
        {
            XHRResponse <bool> result = new XHRResponse <bool>();

            try
            {
                Receipt receipt = _receiptRepository.GetById(receiptId, userId);
                ThrowExceptionIfReceiptDoesntExists(receipt);

                _receiptRepository.Delete(receipt);
                _receiptRepository.Save();

                result.Data      = true;
                result.Succeeded = true;
            }
            catch (Exception ex)
            {
                result.Message   = "Unable to delete receipt.";
                result.Succeeded = false;
            }

            return(result);
        }
 public Receipt Delete(int id)
 {
     return(_receiptRepository.Delete(id));
 }