private MachineWatch ParseFunctionModelToDtoModel(SubscribeToMachineModel stmm) { AlarmSystem.Core.Entity.DB.Machine machine = _machineService.GetMachineById(stmm.MachineId); MachineWatch mw = new MachineWatch() { Machine = machine, WatchId = stmm.WatchId }; return(mw); }
public async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "subscribeToMachine")] HttpRequest req, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); SubscribeToMachineModel stmm = JsonConvert.DeserializeObject <SubscribeToMachineModel>(requestBody); try { MachineWatch mw = ParseFunctionModelToDtoModel(stmm); _watchservice.SubscribeToMachine(mw); return(new OkResult()); } catch (EntityNotFoundException e) { return(new BadRequestObjectResult(e.Message)); } }