Exemple #1
0
        public override async Task <Result> ReceiveAsync(EventData <PowerSourceChangeData> @event)
        {
            var data = @event.Value;

            if (data.RobotId == new Guid(88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
            {
                throw new DivideByZeroException("The mystery 88 guid can't be divided by zero.");
            }

            var robot = await _mgr.GetAsync(data.RobotId);

            if (robot == null)
            {
                return(Result.DataNotFound());
            }

            robot.AcceptChanges();
            robot.PowerSource = data.PowerSource;
            if (robot.IsChanged)
            {
                await _mgr.UpdateAsync(robot, data.RobotId);
            }

            Logger.LogInformation("A trace message to prove it works!");

            if (GetOriginatingData() == null)
            {
                Logger.LogError("There should always be originating data!");
            }

            return(Result.Success());
        }
Exemple #2
0
        public override async Task <Result> ReceiveAsync(EventData <string> @event)
        {
            _log.LogInformation("A trace message to prove it works!");

            if (@event.Key is Guid id)
            {
                var robot = await _mgr.GetAsync(id);

                if (robot == null)
                {
                    return(Result.DataNotFound());
                }

                robot.AcceptChanges();
                robot.PowerSource = @event.Value;
                if (robot.IsChanged)
                {
                    await _mgr.UpdateAsync(robot, id);
                }

                return(Result.Success());
            }
            else
            {
                return(Result.InvalidData($"Key '{@event.Key}' must be a GUID.", ResultHandling.ContinueWithAudit));
            }
        }
 public IActionResult Update([FromBody] Robot value, Guid id)
 {
     return(new WebApiPut <Robot>(this, () => _manager.UpdateAsync(WebApiActionBase.Value(value), id),
                                  operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null));
 }