示例#1
0
        public IEnumerable <IncomeJsonModel> GetIncomesForView(int id)
        {
            List <IncomeJsonModel> jsonModels = new List <IncomeJsonModel>();

            var incomes = from i in _context.Incomes
                          join inc in _context.IncCategories on i.Id equals inc.IncomeId
                          join c in _context.IncomeCategories on inc.IncomeCategoryId equals c.Id
                          where (i.CashAccount.Id == id)
                          select new
            {
                Id             = i.Id,
                Amount         = i.Amount,
                Category       = c.Name,
                Note           = i.Note,
                Date           = i.Date,
                CashAccount_Id = i.CashAccount.Id
            };

            foreach (var i in incomes)
            {
                var income = new IncomeJsonModel()
                {
                    Id             = i.Id,
                    Amount         = i.Amount,
                    Category       = i.Category,
                    Note           = i.Note,
                    Date           = i.Date,
                    CashAccount_Id = i.CashAccount_Id
                };
                jsonModels.Add(income);
            }
            return(jsonModels);
        }
示例#2
0
        public async Task <HttpResponseMessage> CreateIncome(string url, string accessToken,
                                                             IncomeJsonModel content)
        {
            var response = await _clientFactory.CreateClient(accessToken)
                           .PostAsJsonAsync(url, content);

            return(response.EnsureSuccessStatusCode());
        }
        public async Task <IActionResult> Update(IncomeJsonModel incomeJson)
        {
            if (incomeJson == null)
            {
                return(BadRequest());
            }
            if (!_incomeRepository.Exists(incomeJson.Id))
            {
                return(NotFound());
            }
            var income = _mapper.Map <IncomeJsonModel, Income>(incomeJson);
            await _incomeRepository.Update(income);

            return(Ok());
        }
        public async Task <IActionResult> Create(IncomeJsonModel incomeJson)
        {
            if (incomeJson == null)
            {
                return(BadRequest());
            }

            var incomeCategory = await _incomeCategoryRepository.GetItemByName(incomeJson.Category);

            var income = _mapper.Map <IncomeJsonModel, Income>(incomeJson);

            income.Date = DateTime.Now;

            await _incomeRepository.Create(income, incomeJson.CashAccount_Id);

            await _incomeRepository.CreateComunication(
                await _incomeRepository.GetItemByDate(income.Date), incomeCategory);

            return(Ok());
        }
        public async Task <IActionResult> Create(IncomeViewModel incomeViewModel)
        {
            if (ModelState.IsValid)
            {
                var accessToken = await HttpContext.GetTokenAsync("access_token");

                IncomeJsonModel income = _mapper.Map <IncomeViewModel,
                                                      IncomeJsonModel>(incomeViewModel);

                income.CashAccount_Id = CashAccount_Id;
                var result = await _incomeRepository.CreateIncome(
                    "https://localhost:44382/Income/Create", accessToken, income);

                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index", "Income", income.CashAccount_Id));
                }
            }
            return(View(incomeViewModel));
        }