Example #1
0
        public ActionResult <IncomeDto> DepositToBank([FromBody] IncomeDto dto)
        {
            var incomeCreationResult = _incomeService.Create(dto);

            _transactionService.CreateIncomeTransaction(incomeCreationResult);
            return(Ok(incomeCreationResult));
        }
Example #2
0
 private static void ConfigureDtoMapper(this IServiceCollection services)
 {
     services.AddAutoMapper(config =>
     {
         IncomeDto.ApplyMappingConfiguration(config);
         FixedCostDto.ApplyMappingConfiguration(config);
     });
 }
        public async Task Put(string incomeId, IncomeDto incomeDto)
        {
            var income = await _incomes.Find(i => i.Id == incomeId).FirstOrDefaultAsync();

            income.Description = incomeDto.Description;
            income.Value       = incomeDto.Value;

            _incomes.ReplaceOne(e => e.Id == incomeId, income);
        }
Example #4
0
        public IncomeDto CreateIncome(IncomeDto item)
        {
            var entityIncome = _mapper.Map <Income>(item);

            var newIncomeItem = _unitOfWork.IncomeRepository.Add(entityIncome);

            _unitOfWork.Commit();

            return(_mapper.Map <IncomeDto>(newIncomeItem));
        }
        public async Task <IActionResult> Post([FromBody] IncomeDto incomeDto)
        {
            var command = new CalculateIncomeTaxCommand()
            {
                AnnualIncome = incomeDto.AnnualIncome,
                PostCode     = incomeDto.PostCode
            };

            var result = await _mediator.Send(command);

            return(result is null?BadRequest(result) : (IActionResult)Created("Income Tax Calculation created", result));
        }
Example #6
0
 public Boolean deleteIncome(IncomeDto obj)
 {
     try
     {
         IIncomeSvc svc = (IIncomeSvc)this.getService(typeof(IIncomeSvc).Name);
         return svc.deleteIncome(obj);
     }
     catch (ServiceLoadException ex)
     {
         return false;
     }
 }
Example #7
0
 public IncomeDto selectIncomeById(IncomeDto obj)
 {
     try
     {
         IIncomeSvc svc = (IIncomeSvc)this.getService(typeof(IIncomeSvc).Name);
         return svc.selectIncomeById(obj);
     }
     catch (ServiceLoadException ex)
     {
         return null;
     }
 }
Example #8
0
        public ActionResult SaveIncome([FromBody] IncomeDto income)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            income.UserId = UserId;

            _incomeService.SaveIncome(income);

            return(Ok(income.Id));
        }
Example #9
0
        public async Task <IncomeDto> AddIncomeAsync(IncomeDto incomeDto, string userId)
        {
            var income = _mapper.Map <Income>(incomeDto);

            income.Id     = null;
            income.UserId = userId;
            await _incomeRepository.CreateAsync(income);

            var result = await _incomeRepository.SaveAsync();

            //if(result == 0) throw sth;
            return(_mapper.Map <IncomeDto>(income));
        }
Example #10
0
        public IncomeDto UpdateIncome(int id, IncomeDto item)
        {
            var entityIncome   = _mapper.Map <Income>(item);
            var existingIncome = _unitOfWork.IncomeRepository.FindById(entityIncome.IncomeId);

            if (existingIncome != null)
            {
                var newIncome = _unitOfWork.IncomeRepository.Update(id, entityIncome);
                return(_mapper.Map <IncomeDto>(newIncome));
            }
            else
            {
                return(CreateIncome(item));
            }
        }
Example #11
0
        public async Task <IncomeDto> UpdateIncomeAsync(IncomeDto income)
        {
            Income original = await _context.Incomes.FindAsync(income.Id);

            original.Name        = income.Name;
            original.OrderNumber = income.OrderNumber;
            original.Price       = income.Price;

            await _context.SaveChangesAsync();

            income.Id          = original.Id;
            income.Name        = original.Name;
            income.OrderNumber = original.OrderNumber;
            income.Price       = original.Price;
            return(income);
        }
Example #12
0
        public async Task <IncomeDto> CreateIncomeForUserAsync(IncomeDto income, string userId)
        {
            var bodyContent = new StringContent(JsonSerializer.Serialize(income), Encoding.UTF8, "application/json");

            var refreshResult = await _client.PostAsync("api/income/createforuser", bodyContent);

            if (!refreshResult.IsSuccessStatusCode)
            {
                throw new Exception(refreshResult.ToString());
            }

            var refreshContent = await refreshResult.Content.ReadAsStringAsync();

            return(JsonSerializer.Deserialize <IncomeDto>(refreshContent, new JsonSerializerOptions {
                PropertyNameCaseInsensitive = true
            }));
        }
Example #13
0
        public async Task <IncomeDto> CreateIncomeForUserAsync(IncomeDto income, string userId)
        {
            var newIncome = new Income
            {
                Name        = income.Name,
                OrderNumber = income.OrderNumber,
                Price       = income.Price,
                UserId      = userId
            };
            await _context.Incomes.AddAsync(newIncome);

            await _context.SaveChangesAsync();

            income.Id          = newIncome.Id;
            income.Name        = newIncome.Name;
            income.OrderNumber = newIncome.OrderNumber;
            income.Price       = newIncome.Price;

            return(income);
        }
Example #14
0
        public async Task <Income> NewIncomeAsync(IncomeRequest request, string userId)
        {
            var incomeDto = new IncomeDto
            {
                UserId      = userId,
                CreatedAt   = DateTime.UtcNow,
                IncomeDate  = request.IncomeDate,
                Name        = request.Name,
                Description = request.Description,
                IncomeValue = request.IncomeValue,
                CurrencyId  = request.CurrencyId,
                PeriodId    = request.PeriodId
            };

            var income = _mapper.Map <Income>(incomeDto);

            var created = await _baseRepository.CreateEntityAsync(income);

            return(created);
        }
Example #15
0
        public IActionResult Update([FromBody] IncomeDto dto)
        {
            try
            {
                if (dto == null || !ModelState.IsValid)
                {
                    return(BadRequest("Invalid State"));
                }

                var success = _basicIncomeService.Update(dto.Id, DateTime.Parse(dto.Date), dto.Name, dto.Amount, dto.Notes);

                return(Ok(new UpdateResultDto
                {
                    Success = success,
                    Error = success ? "" : "Invalid income information"
                }));
            }
            catch (Exception)
            {
                return(BadRequest("Error while updating"));
            }
        }
Example #16
0
        public async Task <IncomeDto> EditIncomeAsync(IncomeDto incomeDto, string userId)
        {
            var income = await _incomeRepository.FindByIdAsync(incomeDto.Id);

            if (!income.UserId.Equals(userId, StringComparison.OrdinalIgnoreCase))
            {
                throw new IncomeException("Cannot find income", 404);
            }

            income.Value       = incomeDto.Value;
            income.Date        = incomeDto.Date;
            income.CategoryId  = incomeDto.CategoryId;
            income.Description = incomeDto.Description;

            var result = await _incomeRepository.SaveAsync();

            if (result < 1)
            {
                throw new IncomeException("Cannot edit income", 500);
            }

            return(_mapper.Map <IncomeDto>(income));
        }
Example #17
0
        public IActionResult Add([FromBody] IncomeDto dto)
        {
            try
            {
                if (dto == null || !ModelState.IsValid)
                {
                    return(BadRequest("Invalid State"));
                }

                var result = _basicIncomeService.Add(DateTime.Parse(dto.Date), dto.Name, dto.Amount, dto.Notes);

                if (result == null)
                {
                    return(BadRequest("Invalid income data"));
                }

                return(Ok(new IncomeDto(result)));
            }
            catch (Exception)
            {
                return(BadRequest("Error while adding income"));
            }
        }
Example #18
0
 public void UpdateIncome(int id, [FromBody] IncomeDto item)
 {
     _incomeService.UpdateIncome(id, item);
 }
Example #19
0
 public Task <IncomeDto> UpdateIncomeAsync(IncomeDto income) => _provider.UpdateIncomeAsync(income);
Example #20
0
 public Task <IncomeDto> CreateIncomeForUserAsync(IncomeDto income, string userId) => _provider.CreateIncomeForUserAsync(income, userId);
Example #21
0
 public void CreateIncome([FromBody] IncomeDto item)
 {
     _incomeService.CreateIncome(item);
 }
Example #22
0
 public async Task <IActionResult> UpdateIncome([FromBody] IncomeDto income) =>
 Ok(await _incomeService.UpdateIncomeAsync(income));
Example #23
0
 public async Task <IActionResult> CreateIncomeForUser([FromBody] IncomeDto income) =>
 Ok(await _incomeService.CreateIncomeForUserAsync(income, User.GetIdentifier()));
Example #24
0
        public async Task <IActionResult> Put(string incomeId, [FromBody] IncomeDto IncomeDto)
        {
            await _incomesRepository.Put(incomeId, IncomeDto);

            return(Ok());
        }
        public async Task <IActionResult> EditIncome([FromBody] IncomeDto incomeDto)
        {
            var result = await _incomeService.EditIncomeAsync(incomeDto, User.Identity.Name);

            return(Ok(result));
        }
        public async Task <IActionResult> AddIncome([FromBody] IncomeDto incomeDto)
        {
            var income = await _incomeService.AddIncomeAsync(incomeDto, User.Identity.Name);

            return(CreatedAtRoute("GetIncome", new { incomeId = income.Id }, income));
        }