Exemplo n.º 1
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));
        }