コード例 #1
0
        /// <summary>
        /// Updates <paramref name="machine"/> with new data from <paramref name="update"/>. Null values are ignored.
        /// </summary>
        /// <param name="machine">the machine to be updated.</param>
        /// <param name="update">the update data.</param>
        public static void PatchData(this Machine machine, UpdateMachineCommand update)
        {
            WhenNotNull(update.FabricSerialnumber, x => machine.FabricSerialnumber = x);
            WhenNotNull(update.InternalSeriesName, x => machine.InternalSeriesName = x);
            WhenNotNull(update.MachineName, x => machine.MachineName                   = x);
            WhenNotNull(update.ManufacturerName, x => machine.ManufacturerName         = x);
            WhenNotNull(update.PlaceOfManufacturing, x => machine.PlaceOfManufacturing = x);
            WhenNotNull(update.Serialnumber, x => machine.Serialnumber                 = x);

            if (update.ManufacturingYear.HasValue)
            {
                machine.ManufacturingYear = update.ManufacturingYear.Value;
            }
コード例 #2
0
        public async Task <Machine> UpdateMachineAsync(UpdateMachineCommand updateMachineCommand)
        {
            Machine machine = await GetMachineAsync(Guid.Parse(updateMachineCommand.Id));

            if (machine is null)
            {
                return(machine);
            }
            else
            {
                machine.PatchData(updateMachineCommand);

                return(await _repo.UpdateMachineAsync(machine));
            }
        }
コード例 #3
0
        public async Task <ActionResult <Machine> > Put(string id, [FromBody] UpdateMachineCommand update)
        {
            // Example of bare bones input validation.
            // Ensure that route and body reference the same id
            if (update.Id != id)
            {
                return(BadRequest(id));
            }

            var updatedMachine = await _machineService.UpdateMachineAsync(update);

            if (updatedMachine == null)
            {
                return(NotFound(id));
            }

            return(updatedMachine);
        }
コード例 #4
0
        public async Task <ActionResult <Machine> > Patch(string id, [FromBody] UpdateMachineCommand machineUpdate)
        {
            // Example of bare bones input validation. Ensure that
            // - route and body reference the same id
            // - id is a proper Guid
            if ((machineUpdate.Id != id) || (!Guid.TryParse(machineUpdate.Id, out var _)))
            {
                return(BadRequest());
            }

            var updatedMachine = await _machineService.UpdateMachineAsync(machineUpdate);

            if (updatedMachine == null)
            {
                return(NotFound());
            }

            return(updatedMachine);
        }
コード例 #5
0
        public async Task <IHttpActionResult> Update([FromUri] long id, [FromUri] long machineId, [FromBody] UpdateMachineCommand command)
        {
            command.AccountId = id;
            command.MachineId = machineId;

            return(Ok(await Mediator.Send(command)));
        }