private void FireTrigger(Trigger trigger, MobileDataEntity mobileDataEntity, Order inProgressOrder)
 {
     MobileDataEntity = mobileDataEntity;
     InProgressOrder  = inProgressOrder;
     machine.Fire(trigger);
     mobileDataEntity.State     = machine.State.ToString();
     mobileDataEntity.UpdatedAt = dateTimeCreator.Create();
 }
Beispiel #2
0
        public IActionResult Post([FromBody] ActivationCodeToAdd activationCodeToAdd)
        {
            var isSuccess = false;

            using (dataStore.BeginTransaction())
            {
                var existing = dataStore.GetActivationCode(activationCodeToAdd.PhoneNumber);

                if (existing != null)
                {
                    logger.LogDebug("Existing Activation Code for PhoneNumber {phoneNumber}", activationCodeToAdd.PhoneNumber);
                    var updatedAt = dateTimeCreator.Create();
                    logger.LogDebug("Updating Activation Code at {updatedAt}", updatedAt);

                    isSuccess = dataStore.UpdateActivationCode(
                        new ActivationCode
                    {
                        Id          = existing.Id,
                        PhoneNumber = existing.PhoneNumber,
                        Code        = activationCodeToAdd.ActivationCode,
                        UpdatedAt   = updatedAt
                    });
                }
                else
                {
                    isSuccess = dataStore.InsertActivationCode(
                        new ActivationCode
                    {
                        PhoneNumber = activationCodeToAdd.PhoneNumber,
                        Code        = activationCodeToAdd.ActivationCode
                    });
                }
            }

            if (!isSuccess)
            {
                logger.LogError("Failed to save ActivationCode for PhoneNumber {phoneNumber}", activationCodeToAdd.PhoneNumber);
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }

            return(new OkResult());
        }