コード例 #1
0
        public HttpResponseMessage DeleteDebtById([FromUri] int debtId)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            String           Message          = validates.ValidateDelete(debtId);

            if (Message == String.Empty)
            {
                Debt    debt = new Debt();
                Boolean sucess;

                if (debtRepository == null)
                {
                    DebtRepository debtRepository = new DebtRepository();
                    debt = debtRepository.GetDebtById(debtId);

                    if (debt != null)
                    {
                        sucess = debtRepository.DeleteObject(debt, true);

                        if (sucess)
                        {
                            return(new HttpResponseMessage(HttpStatusCode.NoContent));
                        }
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not delete record."));
                    }
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Register not found."));
                }
                else
                {
                    debt   = debtRepository.GetDebtById(debtId);
                    sucess = debtRepository.DeleteObject(debt, true);

                    if (sucess)
                    {
                        return(new HttpResponseMessage(HttpStatusCode.NoContent));
                    }
                }
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Register not found."));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, Message));
        }