Как вызвать App Center Push из моего веб-API asp.net?
Я делаю андроид Xamarin.Android
, Я закончил приложение для Android, и теперь я хочу добавить удаленные push-уведомления на основе моего состояния элемента в моей базе данных, к которой можно получить доступ из ASP.Net Web Api
,
Мне удалось отправить уведомление из App Center Push в мое приложение. Я уже авторизовал клиент App Center и теперь могу получить доступ к api app center. Я планирую объединить API-интерфейс App Center с моим asp.net web api
если возможно. Но я не знаю с чего начать.
Должен ли я поместить действие центра приложений на мой контроллер (я не знаю, работает ли он или нет) или есть другой способ? вот мой контроллер: открытый класс InventoriesController: ApiController { private InventoryRepository _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;
}
И это моя модель:
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;
}
}
Я хочу, чтобы центр приложений отправлял уведомления на основе даты истечения срока действия на мой Inventories model
а также AddedUserId
, Так что это мой веб сам сделал web api
кто отправляет уведомления в мои приложения. Я прочитал эту документацию: [ https://docs.microsoft.com/en-us/appcenter/push/pushapi][1] но до сих пор не знаю, куда мне писать в моем Web Api
,
Надеюсь, кто-то здесь может мне помочь. Заранее спасибо:)
0 ответов
Вы можете найти подробности здесь в документации API REST appcenter https://docs.microsoft.com/en-us/appcenter/push/rest-api
API REST API Appcenter: https://openapi.appcenter.ms/