// override to balance the register after adding new entry
        public override async Task <bool> Create(RegisterEntry entry)
        {
            bool status = await base.Create(entry);

            if (!status)
            {
                return(false);
            }

            return(await _registerRepo.Balance(entry.RegisterId, entry.UserId));
        }
Пример #2
0
        public async Task <IActionResult> Balance(ControllerBase controller,
                                                  IRegisterRepository repo, int id)
        {
            try
            {
                string desc = GetControllerDescription(controller);
                _logger.LogInfo(desc);
                if (id < 1)
                {
                    _logger.LogWarn($"{desc}: Empty request submitted");
                    return(controller.BadRequest());
                }
                var user = await _userService.GetCurrentUser();

                if (user == null)
                {
                    _logger.LogWarn($"{desc}: Invalid request submitted - Not a valid user");
                    return(controller.BadRequest());
                }
                var exists = await repo.Exists(id, user?.Id);

                if (!exists)
                {
                    _logger.LogWarn($"{desc}: Item with id {id} was not found or does not belong to {user?.Email}");
                    return(controller.NotFound());
                }

                var isSuccess = await repo.Balance(id, user?.Id);

                if (!isSuccess)
                {
                    return(InternalError(controller, $"{desc}: Balance failed"));
                }
                _logger.LogInfo($"{desc}: Balance Successful");
                return(controller.Ok());
            }
            catch (Exception e)
            {
                return(InternalError(controller, $"Server Error: {e.Message} - {e.InnerException}"));
            }
        }