public async Task <ActionResult <Debt> > PostDebt([FromBody] Debt debt) { _respository.Insert(debt); await _service.recalculate(debt); await _respository.Save(); return(CreatedAtAction(nameof(Debt), new { id = debt.Id }, debt)); }
public HttpResponseMessage CreateDebt([FromBody] DebtViewModel debtAttribute) { Validates validates = new Validates(); MessageViewModel messageAttribute = new MessageViewModel(); var Message = validates.ValidateDebt(debtAttribute); if (Message == String.Empty) { Debt debt = new Debt(); Boolean sucess; if (debtRepository == null) { DebtRepository debtRepository = new DebtRepository(); debt.Value = Convert.ToDecimal(debtAttribute.Value); debt.Date = Convert.ToDateTime(debtAttribute.Date); debt.Description = debtAttribute.Description; FriendRepository friendName = new FriendRepository(); debt.FriendIdIn = friendName.GetFriendIdByName(debtAttribute.FriendNameIn); debt.FriendIdOut = friendName.GetFriendIdByName(debtAttribute.FriendNameOut); sucess = debtRepository.Insert(debt); if (sucess) { return(Request.CreateResponse(HttpStatusCode.Created, messageAttribute.Create())); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not create debit.")); } else { sucess = debtRepository.Insert(debt); if (sucess) { return(Request.CreateResponse(HttpStatusCode.Created, messageAttribute.Create())); } } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not create debit.")); } return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, Message)); }