Exemplo n.º 1
0
        public IHttpActionResult Post(IncomeRequest Income)
        {
            var result = IncomeService.CreateIncome(Income);

            return(Created <Entidad>("", new Entidad {
                Id = result.Id
            }));
        }
Exemplo n.º 2
0
        public ActionResult Index(IncomeRequest request)
        {
            var model = new Income();
            //this.RenderMyViewData(model);
            var result = this.ProjectService.GetIncomeList(request);

            return(View(result));
        }
Exemplo n.º 3
0
        // PUT api/<controller>/5
        /// <summary>
        /// Modifica un Income
        /// </summary>
        /// <param name="Income">Income a modificar</param>
        /// <returns></returns>
        public IHttpActionResult Put(int id, IncomeRequest Income)
        {
            var originalIncome = IncomeService.GetById(id);

            var ret = IncomeService.UpdateIncome(originalIncome, Income);

            return(Ok());
        }
Exemplo n.º 4
0
 private void MergeIncome(Income originalIncome, IncomeRequest Income)
 {
     originalIncome.Consortium  = this.ConsortiumRepository.GetById(Income.ConsortiumId);
     originalIncome.Type        = this.IncomeTypeRepository.GetById(Income.IncomeTypeId);
     originalIncome.Amount      = Income.Amount;
     originalIncome.Description = Income.Description;
     originalIncome.IncomeDate  = Income.IncomeDate;
 }
Exemplo n.º 5
0
        public Income CreateIncome(IncomeRequest Income)
        {
            var entityToInsert = new Income()
            {
            };

            MergeIncome(entityToInsert, Income);
            IncomeRepository.Insert(entityToInsert);
            return(entityToInsert);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> CreateIncome([FromBody] IncomeRequest request)
        {
            var userId = User.Claims.FirstOrDefault(c => c.Type == "id").Value;

            // check if user exists
            var userExists = await _identityService.CheckIfUserExists(userId);

            if (!userExists)
            {
                return(NotFound(new ErrorResponse(new ErrorModel {
                    Message = $"There is no user with id: {userId}"
                })));
            }

            var budget = await _budgetService.GetBudgetAsync(request.BudgetId);

            if (budget == null)
            {
                return(NotFound(new ErrorResponse(new ErrorModel {
                    Message = $"There is no budget with id: {request.BudgetId}"
                })));
            }

            if (budget.UserId != userId)
            {
                return(Forbid());
            }


            var period = await _periodService.GetPeriodAsync(request.PeriodId);

            if (period == null)
            {
                return(NotFound(new ErrorResponse(new ErrorModel {
                    Message = $"There is no Period with id: {request.PeriodId} in Budget with id: {request.BudgetId}"
                })));
            }


            var income = await _incomeService.NewIncomeAsync(request, userId);

            if (income == null)
            {
                return(BadRequest());
            }

            var locationUri = _uriService.GetIncomeUri(income.Id);

            return(Created(locationUri, new Response <IncomeResponse>(_mapper.Map <IncomeResponse>(income))));
        }
Exemplo n.º 7
0
        public IEnumerable <Income> GetIncomeList(IncomeRequest request = null)
        {
            request = request ?? new IncomeRequest();
            using (var dbContext = new ProjectDbContext())
            {
                IQueryable <Income> Income = dbContext.Incomes;

                if (!string.IsNullOrEmpty(request.RecObject))
                {
                    Income = Income.Where(u => u.RecObject.Contains(request.RecObject));
                }

                return(Income.OrderByDescending(u => u.ID).ToPagedList(request.PageIndex, request.PageSize));
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 public Income UpdateIncome(Income originalIncome, IncomeRequest Income)
 {
     this.MergeIncome(originalIncome, Income);
     IncomeRepository.Update(originalIncome);
     return(originalIncome);
 }
Exemplo n.º 10
0
 public bool UpdateIncome(IncomeRequest Income)
 {
     return(IntegrationService.RestCallNoReturn(ConfigurationManager.AppSettings["ApiCoreUrl"], string.Format(ApiCore.UpdateIncome, Income.Id), RestMethod.Put, null, Income));
 }
Exemplo n.º 11
0
 public bool CreateIncome(IncomeRequest Income)
 {
     return(IntegrationService.RestCallNoReturn(ConfigurationManager.AppSettings["ApiCoreUrl"], ApiCore.CreateIncome, RestMethod.Post, null, Income));
 }