mirror of https://gitee.com/IoTSharp/Gateways.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using IoTSharp.Gateway.Modbus.Data;
|
|
|
|
namespace IoTSharp.Gateway.Modbus.Pages.PointMapAdmin
|
|
{
|
|
public class CreateModel : PageModel
|
|
{
|
|
private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context;
|
|
|
|
public CreateModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public IActionResult OnGet(Guid? id)
|
|
{
|
|
return Page();
|
|
}
|
|
|
|
[BindProperty]
|
|
public PointMapping PointMapping { get; set; } = default!;
|
|
|
|
|
|
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
|
|
public async Task<IActionResult> OnPostAsync(Guid id)
|
|
{
|
|
var owner = _context.ModbusSlaves.Find(id);
|
|
if (!ModelState.IsValid || _context.PointMappings == null || PointMapping == null || owner==null)
|
|
{
|
|
return Page();
|
|
}
|
|
PointMapping.Id = Guid.NewGuid();
|
|
PointMapping.Owner = owner;
|
|
_context.PointMappings.Add(PointMapping);
|
|
await _context.SaveChangesAsync();
|
|
return RedirectToPage($"./Index", id);
|
|
}
|
|
}
|
|
}
|