Exemple #1
0
        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));
        }
Exemple #2
0
        // GET: api/ExpectedIncomes/5
        public IActionResult GetExpectedIncomes(int id)
        {
            ExpectedIncome expectedIncome = apiContext.ExpectedIncomes.FirstOrDefault(e => e.ExpectedIncomeId == id);

            if (expectedIncome == null)
            {
                return(HttpNotFound());
            }
            expectedIncome.decryptValue();
            return(new ObjectResult(expectedIncome));
        }
Exemple #3
0
        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));
        }