public async Task <IActionResult> Create(CreateMachineViewModel model, CancellationToken ct) { ct.ThrowIfCancellationRequested(); if (ModelState.IsValid) { var machine = await _machineService.CreateMachine(model, ct); await _context.Entry(machine) .Collection(d => d.Drinks) .Query() .Include(d => d.Drink) .ThenInclude(i => i.Image) .LoadAsync(ct); await _context.Entry(machine) .Collection(c => c.Coins) .Query() .Include(c => c.Coin) .ThenInclude(i => i.Image) .LoadAsync(ct); await _adminHub.Clients.All.AddMachine(machine); return(RedirectToAction(nameof(Index), "Admin")); } return(View(model)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "machines")] HttpRequest req, ILogger log) { _machineService.CreateMachine(); return(new OkResult()); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "machines")] HttpRequest req, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var cmm = JsonConvert.DeserializeObject <CreateMachineModel>(requestBody); AlarmSystem.Core.Entity.DB.Machine machine = new AlarmSystem.Core.Entity.DB.Machine { Name = cmm.Name, Type = cmm.Type }; try { _machineService.CreateMachine(machine); return(new OkResult()); } catch (InvalidDataException ex) { return(new BadRequestObjectResult(ex.Message)); } }