public IActionResult PostExpectedIncome([FromBody] ExpectedIncome expectedIncome) { ApplicationUser currentUser = getCurrentUser(); expectedIncome.User = currentUser; if (!ModelState.IsValid) { return(HttpBadRequest(ModelState)); } if (expectedIncome.ExpectedIncomeId != 0) { expectedIncome.encryptValue(); UpdateExpectedIncome(expectedIncome); expectedIncome.decryptValue(); return(new ObjectResult(expectedIncome)); } IQueryable <ExpectedIncome> allExpectedIncomes = apiContext.ExpectedIncomes.Include(b => b.User); foreach (ExpectedIncome expectedIncomeItem in allExpectedIncomes) { if (expectedIncomeItem.User.Id == expectedIncome.User.Id && expectedIncomeItem.Name == expectedIncome.Name && expectedIncome.ExpectedIncomeId == 0 && expectedIncomeItem != null) { return(findExpectedIncomeToUpdate(expectedIncomeItem, expectedIncome)); } } expectedIncome.encryptValue(); apiContext.ExpectedIncomes.Add(expectedIncome); apiContext.SaveChanges(); expectedIncome.decryptValue(); return(new ObjectResult(expectedIncome)); }
public IActionResult PutExpectedIncome(int id, [FromBody] ExpectedIncome expectedIncome) { if (!ModelState.IsValid) { return(HttpBadRequest(ModelState)); } if (id != expectedIncome.ExpectedIncomeId) { return(HttpBadRequest()); } expectedIncome.encryptValue(); expectedIncome.User = getCurrentUser(); apiContext.Entry(expectedIncome).State = EntityState.Modified; try { apiContext.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ExpectedIncomeExists(id)) { return(HttpNotFound()); } else { throw; } } return(new NoContentResult()); }
private IActionResult findExpectedIncomeToUpdate(ExpectedIncome expectedIncomeItem, ExpectedIncome expectedIncome) { ApplicationUser currentUser = getCurrentUser(); if (expectedIncomeItem.User.UserName != currentUser.UserName) { return(HttpBadRequest()); } expectedIncomeItem.Value = expectedIncome.Value; expectedIncomeItem.EncryptedValue = expectedIncome.EncryptedValue; expectedIncomeItem.Deleted = expectedIncome.Deleted; expectedIncomeItem.encryptValue(); UpdateExpectedIncome(expectedIncomeItem); expectedIncomeItem.decryptValue(); return(new ObjectResult(expectedIncomeItem)); }