Ejemplo n.º 1
0
        public IHttpActionResult PostBudget(BudgetDetailsDto budget)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            db.Budgets.Add(new Budget
            {
                ID            = budget.ID,
                Balance       = budget.Balance,
                PurchaseLogID = budget.PurchaseLogID
            });
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = budget.ID }, budget));
        }
Ejemplo n.º 2
0
        public IHttpActionResult GetBudget(int id)
        {
            Budget           budgetTmp = db.Budgets.Find(id);
            BudgetDetailsDto budget    = new BudgetDetailsDto
            {
                ID            = budgetTmp.ID,
                Balance       = budgetTmp.Balance,
                PurchaseLogID = budgetTmp.PurchaseLogID
            };

            if (budget == null)
            {
                return(NotFound());
            }

            return(Ok(budget));
        }
Ejemplo n.º 3
0
        public IHttpActionResult PutBudget(int id, [FromBody] BudgetDetailsDto budget)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!BudgetExists(id))
            {
                return(BadRequest());
            }

            Budget currentBudget = db.Budgets.Find(id);

            if (id != currentBudget.ID)
            {
                return(BadRequest());
            }

            db.Entry(currentBudget).State = EntityState.Modified;
            currentBudget = new Budget
            {
                ID            = budget.ID,
                Balance       = budget.Balance,
                PurchaseLogID = budget.PurchaseLogID
            };
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BudgetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public IHttpActionResult DeleteBudget(int id)
        {
            Budget budget = db.Budgets.Find(id);

            if (budget == null)
            {
                return(NotFound());
            }

            db.Budgets.Remove(budget);
            db.SaveChanges();

            BudgetDetailsDto response = new BudgetDetailsDto
            {
                ID            = budget.ID,
                Balance       = budget.Balance,
                PurchaseLogID = budget.PurchaseLogID
            };

            return(Ok(response));
        }