Пример #1
0
        public IActionResult GetById([FromRoute] int id)
        {
            var actionResult = new CustomActionResultEntity <VendingMachine>
            {
                Successful = true
            };

            var vendingMachine = _vendingMachineService.GetById(id);

            if (vendingMachine == null)
            {
                actionResult.Successful = false;
                actionResult.Message    = "Vending Machine do not exist!";

                return(Ok(actionResult));
            }
            actionResult.Entity = vendingMachine;

            return(Ok(actionResult));
        }
Пример #2
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));
        }
Пример #3
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));
        }