Exemplo n.º 1
0
        public IActionResult Create([FromBody] Defect request)
        {
            var actionResult = new CustomActionResult
            {
                Successful = true,
                Message    = "Defect was successfull created!"
            };

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

                return(Ok(actionResult));
            }

            try
            {
                var vendingMachine = _vendingMachineService.GetById(request.VendingMachineId);
                vendingMachine.CostOfDefects   += decimal.ToInt32(request.Cost);
                vendingMachine.NumberOfDefects += 1;
                _vendingMachineService.Update(vendingMachine);
            }
            catch
            {
                actionResult.Successful = false;
                actionResult.Message    = "Create defect was successfully, but values for the vending machine was not updated properly, please contact the admin!";

                return(Ok(actionResult));
            }

            return(Ok(actionResult));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public IActionResult Update([FromRoute] int id, [FromBody] VendingMachine request)
        {
            var actionResult = new CustomActionResult
            {
                Successful = true,
                Message    = "Update vending machine informations was successfully!"
            };

            try
            {
                request.SetAudit(CurrentLoggedUserId);
                var vendingMachine = _vendingMachineService.Update(request);
                actionResult.EntityId = vendingMachine.Id;
            }
            catch
            {
                actionResult.Successful = false;
                actionResult.Message    = "Update vending machine informations was unsuccessfully, please try again!";

                return(Ok(actionResult));
            }

            return(Ok(actionResult));
        }