Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CreateIncomeViewmodel incomeToCreate)
        {
            var income = _mapper.Map <Income>(incomeToCreate);
            await _authorizationService.HandleCreateUpdateAsync(income);

            var createdIncome = await _incomeService.Create(income);

            var model = _mapper.Map <IncomeViewmodel>(createdIncome);

            return(Created(Request.Path, model));
        }
Ejemplo n.º 2
0
 public ActionResult Post([FromBody] Income income)
 {
     try
     {
         var status = incomeService.Create(income);
         return(Ok(status));
     }
     catch (Exception ex)
     {
         Logger.LogError(ex, "Type: {Type}. Message: {Message}", ex.GetType(), ex.Message);
         return(BadRequest($"{ex.GetType()}: {ex.Message}"));
     }
 }
        public async Task <IActionResult> Create(IncomeInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values));
            }

            try
            {
                var income = mapper.Map <Income>(model);
                await incomeService.Create(income);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 4
0
        public IActionResult Create([FromBody] Income request)
        {
            var actionResult = new CustomActionResult
            {
                Successful = true,
                Message    = "Income was successfully created!"
            };

            try
            {
                request.SetAudit(CurrentLoggedUserId);
                var income = _incomeService.Create(request);
                actionResult.EntityId = income.Id;
            }
            catch
            {
                actionResult.Successful = false;
                actionResult.Message    = "Create income was unsuccessfully, please try again!";

                return(Ok(actionResult));
            }

            try
            {
                var vendingMachine = _vendingMachineService.GetById(request.VendingMachineId);
                vendingMachine.Income += request.CollectedIncome;
                _vendingMachineService.Update(vendingMachine);
            }
            catch
            {
                actionResult.Successful = false;
                actionResult.Message    = "Create income was successfully, but Income value for the vending machine was not updated properly, please contact the admin!";

                return(Ok(actionResult));
            }

            return(Ok(actionResult));
        }