Asp.net web api 如何从我的asp.net Web API触发App Center推送?
我正在做一个安卓Asp.net web api 如何从我的asp.net Web API触发App Center推送?,asp.net-web-api,xamarin.android,android-push-notification,visual-studio-app-center-push,Asp.net Web Api,Xamarin.android,Android Push Notification,Visual Studio App Center Push,我正在做一个安卓Xamarin.android。我完成了android应用程序,现在我想根据数据库中的项目条件添加远程推送通知,该数据库可以从ASP.Net Web Api访问 我成功地将通知从应用程序中心推送到我的应用程序。我已经授权了App Center客户端,现在可以访问App Center api。如果可能的话,我计划将app center api合并到我的asp.net web api。但我不知道从哪里开始 我应该将app center操作放到我的控制器上(我不知道它是否工作)还是有其
Xamarin.android
。我完成了android应用程序,现在我想根据数据库中的项目条件添加远程推送通知,该数据库可以从ASP.Net Web Api
访问
我成功地将通知从应用程序中心推送到我的应用程序。我已经授权了App Center客户端,现在可以访问App Center api。如果可能的话,我计划将app center api合并到我的asp.net web api
。但我不知道从哪里开始
我应该将app center操作放到我的控制器上(我不知道它是否工作)还是有其他方法?
这是我的控制器:
公共类清单控制器:ApiController
{
私有库存存储库(InventoryRepository);
public InventoriesController()
{
_inventoryRepository = new InventoryRepository();
}
// GET: api/Categories
public IHttpActionResult GetInventories()
{
IEnumerable<InventoryViewModel> inv = _inventoryRepository.GetAll().ToList().Select(e=> new InventoryViewModel(e)).ToList();
return Ok(inv);
}
// GET: api/Categories/5
[ResponseType(typeof(InventoryViewModel))]
public IHttpActionResult GetInventory(Guid id)
{
InventoryViewModel inventory = new InventoryViewModel (_inventoryRepository.GetSingle(e => e.Id == id));
if (inventory == null)
{
return NotFound();
}
return Ok(inventory);
}
// PUT: api/Categories/5
[ResponseType(typeof(void))]
public IHttpActionResult PutInventory(Guid id, InventoryViewModel inventory)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != inventory.Id)
{
return BadRequest();
}
try
{
_inventoryRepository.Edit(inventory.ToModel());
}
catch (DbUpdateConcurrencyException)
{
if (!InventoryExist(id))
{
return NotFound();
}
else
{
throw;
}
}
return StatusCode(HttpStatusCode.NoContent);
}
// POST: api/Categories
[ResponseType(typeof(InventoryViewModel))]
public IHttpActionResult PostInventory(InventoryViewModel inventory)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
try
{
_inventoryRepository.Add(inventory.ToModel());
}
catch (DbUpdateException)
{
if (InventoryExist(inventory.Id))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtRoute("DefaultApi", new { id = inventory.Id }, inventory);
}
// DELETE: api/Categories/5
[ResponseType(typeof(Inventory))]
public async Task<IHttpActionResult> DeleteInventory(Guid id)
{
Inventory inventory = _inventoryRepository.GetSingle(e => e.Id == id);
if (inventory == null)
{
return NotFound();
}
await _inventoryRepository.DeleteAsync(inventory);
return Ok(inventory);
}
private bool InventoryExist(Guid id)
{
IQueryable<Inventory> inv = _inventoryRepository.GetAll();
return inv.Count(e => e.Id == id) > 0;
}
我想让应用程序中心根据我的库存模型
和AddedUserId
上的过期日期发送通知。因此,是我的web自制web api
向我的应用程序发送通知。
我读了这篇文档:[但仍然不知道在我的webapi
中应该在哪里编写
希望这里有人能帮我。
提前感谢:)您可以在appcenter REST API文档中找到详细信息
Appcenter REST API招摇过市:你看了吗?我看了。但仍然不知道我应该从我的web API开始。你可以通过登录并单击屏幕右下角的聊天图标来联系App Center支持。你可以在那里获得更好的支持。:)如果你在查找聊天时遇到问题,这里有一个屏幕截图
public class InventoryViewModel
{
public Guid Id { get; set; }
public int Quantity { get; set; }
public DateTime ExpirationDate { get; set; }
public bool IsDeleted { get; set; }
public bool IsConsumed { get; set; }
public decimal Price { get; set; }
public string ItemName { get; set; }
public Guid ProductId { get; set; }
public Guid StorageId { get; set; }
public string AddedUserId { get; set; }
public Inventory ToModel()
{
return new Inventory
{
Id = (Id == Guid.Empty) ? Guid.NewGuid() : Id,
ExpirationDate = ExpirationDate,
Price = Price,
ProductId=ProductId,
StorageId=StorageId,
ItemName=ItemName,
IsDeleted=IsDeleted,
IsConsumed=IsConsumed,
AddedUserId = AddedUserId,
};
}
public InventoryViewModel()
{
}
public InventoryViewModel(Inventory i)
{
this.Id = i.Id;
this.ExpirationDate = i.ExpirationDate;
this.Price = i.Price;
this.ProductId = i.ProductId;
this.StorageId = i.StorageId;
this.ItemName = i.ItemName;
this.AddedUserId = i.AddedUserId;
}
}