提交 de6e9c5d 编写于 作者: 麦壳饼's avatar 麦壳饼

modify api for tenans and customers

上级 5673d1e6
......@@ -20,11 +20,11 @@ namespace IoTSharp.Hub.Controllers
_context = context;
}
// GET: api/Customers
[HttpGet]
public async Task<ActionResult<IEnumerable<Customer>>> GetCustomer()
// GET: api/Tenants
[HttpGet("Tenant/{tenantId}")]
public async Task<ActionResult<IEnumerable<Customer>>> GetCustomers(Guid tenantId)
{
return await _context.Customer.ToListAsync();
return (await _context.Tenant.FindAsync(tenantId)).Customers?.ToList();
}
// GET: api/Customers/5
......@@ -49,9 +49,13 @@ namespace IoTSharp.Hub.Controllers
{
return BadRequest();
}
var tent=await _context.Tenant.FindAsync(customer.Id);
if (tent == null)
{
return NotFound();
}
customer.Tenant = tent;
_context.Entry(customer).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
......@@ -75,10 +79,10 @@ namespace IoTSharp.Hub.Controllers
[HttpPost]
public async Task<ActionResult<Customer>> PostCustomer(Customer customer)
{
customer.Tenant= _context.Tenant.Find(customer.Tenant.Id);
_context.Customer.Add(customer);
await _context.SaveChangesAsync();
return CreatedAtAction("GetCustomer", new { id = customer.Id }, customer);
return await GetCustomer(customer.Id);
}
// DELETE: api/Customers/5
......@@ -101,5 +105,10 @@ namespace IoTSharp.Hub.Controllers
{
return _context.Customer.Any(e => e.Id == id);
}
public class TenantDto
{
public Guid Id { get; set; }
}
}
}
......@@ -92,6 +92,8 @@ namespace IoTSharp.Hub.Controllers
await _signInManager.SignInAsync(user, false);
await _signInManager.UserManager.AddClaimAsync(user, new Claim(ClaimTypes.Email, model.Email));
await _signInManager.UserManager.AddClaimAsync(user, new Claim(ClaimTypes.GroupSid, customer.Id.ToString()));
var rship = new Relationship();
rship.IdentityUser = _context.Users.Find(user.Id);
rship.Customer = customer;
......
......@@ -27,6 +27,7 @@ namespace IoTSharp.Hub.Controllers
return await _context.Tenant.ToListAsync();
}
// GET: api/Tenants/5
[HttpGet("{id}")]
public async Task<ActionResult<Tenant>> GetTenant(Guid id)
......
......@@ -20,6 +20,7 @@ namespace IoTSharp.Hub.Data
public string Address { get; set; }
public int ZipCode { get; set; }
public Tenant Tenant { get; set; }
[Newtonsoft.Json.JsonIgnore]
public List<Device> Devices { get; set; }
}
}
......@@ -19,7 +19,9 @@ namespace IoTSharp.Hub.Data
public string Street { get; set; }
public string Address { get; set; }
public int ZipCode { get; set; }
[Newtonsoft.Json.JsonIgnore]
public List<Customer> Customers { get; set; }
[Newtonsoft.Json.JsonIgnore]
public List<Device> Devices { get; set; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册