如何从我的asp.net的Web API触发应用中心推?

问题描述 投票:0回答:1

我在做一个机器人Xamarin.Android。我完成了Android应用程序,现在我想添加基于我的数据库我的项目状态远程推送通知,可以从ASP.Net Web Api访问。

我成功发送的通知从应用中心推到我的应用程序。我已授权应用中心客户端现在可以访问应用程序中心的API。我打算如果可能的应用程序中心API合并到我的asp.net web api。但我不知道从哪里开始的。

我应该把应用中心采取行动,我的控制器(我不知道它的工作或没有)或者有另一种方式?这里是我的控制器:公共类InventoriesController:ApiController {私人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 modelAddedUserId截止日期应用中心发送通知。所以其我的网络自制谁的通知发送到我的应用程序web api。我阅读本文档:[https://docs.microsoft.com/en-us/appcenter/push/pushapi][1]但还是不知道我有我的Web Api写。

希望这里有人能帮助我。提前致谢 :)

asp.net-web-api xamarin.android android-push-notification visual-studio-app-center-push
1个回答
1
投票

您可以在appcenter REST API文档https://docs.microsoft.com/en-us/appcenter/push/rest-api在这里找到详细

Appcenter REST API招摇:https://openapi.appcenter.ms/

© www.soinside.com 2019 - 2024. All rights reserved.