Beispiel #1
0
        public void Add_Test()
        {
            item.Description  = "bla bla";
            item.SpendingDate = DateTime.Now;
            item.MoneySpent   = 5;

            spendingRepo.Add(item);
        }
        public async Task <IActionResult> Post(SpendingForAddDTO model)
        {
            Spending spending = mapper.Map <Spending>(model);
            //spending.UserId = 1;
            await spendingRepository.Add(spending).ConfigureAwait(true);

            await unitOfWork.CompleteAsync().ConfigureAwait(true);

            return(Ok(mapper.Map <SpendingForGetDTO>(await spendingRepository.Get(spending.Id).ConfigureAwait(true))));
        }
Beispiel #3
0
        public long Add(SpendingRegisterCommand cmd)
        {
            Employee employee = _repositoryEmployee.GetById(cmd.EmployeeId) ?? throw new NotFoundException();

            Spending spending = Mapper.Map <SpendingRegisterCommand, Spending>(cmd);

            spending.Employee = employee;

            Spending newSpending = _repositorySpending.Add(spending);

            return(newSpending.Id);
        }
Beispiel #4
0
 public async Task <IActionResult> Create([Bind("BalanceId", "Category", "Description", "Amount", "Date")] Spending spending)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (await _repository.Add(spending) != null)
             {
                 return(RedirectToAction(nameof(Details), "Balance", new { id = spending.BalanceId }, null));
             }
         }
         catch (Exception)
         {
             throw new Exception("No se pudo cargar el gasto.");
         }
     }
     return(View(spending));
 }
Beispiel #5
0
        public async Task <ActionResult <Spending> > PostSpending(Spending spending)
        {
            var user = await _repository.ValidUser(GetTokenUserId());

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

            if (await _repository.Add(spending, user.Id) == null)
            {
                return(BadRequest());
            }

            await _repository.UpdateBalance(spending.BalanceId);

            return(StatusCode(201));
        }