How to trigger App Center Push from my asp.net Web API?












0















I'm making an android Xamarin.Android. I finished the android application and now I want to add remote push notifications based on my item condition in my database that can accessed from ASP.Net Web Api.



I succeeded sent notifications from App Center Push to my application. I already authorized the App Center Client and now can access the app center api. I'm planning to merge the app center api to my asp.net web api if possible. But I don't know where to start it.



Should I put the app center action to my controller (I don't know if its working or not) or there's another way?
here's my controller:
public class 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;
}


And this is my model:



    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;
}
}


I want to make the app center send notification based on Expired Date on my Inventories model and AddedUserId. So its my web self made web api who send the notification to my apps.
I read this documentation: [https://docs.microsoft.com/en-us/appcenter/push/pushapi][1] but still don't know where I have to write in my Web Api.



Hope someone here can help me.
Thanks in advance :)










share|improve this question

























  • Have you looked at this?

    – G.hakim
    Nov 21 '18 at 7:44











  • I have.. but still no clue where I have to start in my web api.

    – Yeremia Danang
    Nov 21 '18 at 8:44











  • You can reach out to App Center support by logging into appcenter.ms/sign-in?original_url=%2Fapps and clicking the chat icon in the lower right corner of the screen. You could get a better support there. :)

    – York Shen - MSFT
    Nov 22 '18 at 5:05











  • Here's a screenshot if you're having trouble finding the chat icon

    – York Shen - MSFT
    Nov 22 '18 at 5:06
















0















I'm making an android Xamarin.Android. I finished the android application and now I want to add remote push notifications based on my item condition in my database that can accessed from ASP.Net Web Api.



I succeeded sent notifications from App Center Push to my application. I already authorized the App Center Client and now can access the app center api. I'm planning to merge the app center api to my asp.net web api if possible. But I don't know where to start it.



Should I put the app center action to my controller (I don't know if its working or not) or there's another way?
here's my controller:
public class 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;
}


And this is my model:



    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;
}
}


I want to make the app center send notification based on Expired Date on my Inventories model and AddedUserId. So its my web self made web api who send the notification to my apps.
I read this documentation: [https://docs.microsoft.com/en-us/appcenter/push/pushapi][1] but still don't know where I have to write in my Web Api.



Hope someone here can help me.
Thanks in advance :)










share|improve this question

























  • Have you looked at this?

    – G.hakim
    Nov 21 '18 at 7:44











  • I have.. but still no clue where I have to start in my web api.

    – Yeremia Danang
    Nov 21 '18 at 8:44











  • You can reach out to App Center support by logging into appcenter.ms/sign-in?original_url=%2Fapps and clicking the chat icon in the lower right corner of the screen. You could get a better support there. :)

    – York Shen - MSFT
    Nov 22 '18 at 5:05











  • Here's a screenshot if you're having trouble finding the chat icon

    – York Shen - MSFT
    Nov 22 '18 at 5:06














0












0








0








I'm making an android Xamarin.Android. I finished the android application and now I want to add remote push notifications based on my item condition in my database that can accessed from ASP.Net Web Api.



I succeeded sent notifications from App Center Push to my application. I already authorized the App Center Client and now can access the app center api. I'm planning to merge the app center api to my asp.net web api if possible. But I don't know where to start it.



Should I put the app center action to my controller (I don't know if its working or not) or there's another way?
here's my controller:
public class 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;
}


And this is my model:



    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;
}
}


I want to make the app center send notification based on Expired Date on my Inventories model and AddedUserId. So its my web self made web api who send the notification to my apps.
I read this documentation: [https://docs.microsoft.com/en-us/appcenter/push/pushapi][1] but still don't know where I have to write in my Web Api.



Hope someone here can help me.
Thanks in advance :)










share|improve this question
















I'm making an android Xamarin.Android. I finished the android application and now I want to add remote push notifications based on my item condition in my database that can accessed from ASP.Net Web Api.



I succeeded sent notifications from App Center Push to my application. I already authorized the App Center Client and now can access the app center api. I'm planning to merge the app center api to my asp.net web api if possible. But I don't know where to start it.



Should I put the app center action to my controller (I don't know if its working or not) or there's another way?
here's my controller:
public class 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;
}


And this is my model:



    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;
}
}


I want to make the app center send notification based on Expired Date on my Inventories model and AddedUserId. So its my web self made web api who send the notification to my apps.
I read this documentation: [https://docs.microsoft.com/en-us/appcenter/push/pushapi][1] but still don't know where I have to write in my Web Api.



Hope someone here can help me.
Thanks in advance :)







asp.net-web-api xamarin.android android-push-notification visual-studio-app-center-push






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 8:48







Yeremia Danang

















asked Nov 21 '18 at 7:02









Yeremia DanangYeremia Danang

457




457













  • Have you looked at this?

    – G.hakim
    Nov 21 '18 at 7:44











  • I have.. but still no clue where I have to start in my web api.

    – Yeremia Danang
    Nov 21 '18 at 8:44











  • You can reach out to App Center support by logging into appcenter.ms/sign-in?original_url=%2Fapps and clicking the chat icon in the lower right corner of the screen. You could get a better support there. :)

    – York Shen - MSFT
    Nov 22 '18 at 5:05











  • Here's a screenshot if you're having trouble finding the chat icon

    – York Shen - MSFT
    Nov 22 '18 at 5:06



















  • Have you looked at this?

    – G.hakim
    Nov 21 '18 at 7:44











  • I have.. but still no clue where I have to start in my web api.

    – Yeremia Danang
    Nov 21 '18 at 8:44











  • You can reach out to App Center support by logging into appcenter.ms/sign-in?original_url=%2Fapps and clicking the chat icon in the lower right corner of the screen. You could get a better support there. :)

    – York Shen - MSFT
    Nov 22 '18 at 5:05











  • Here's a screenshot if you're having trouble finding the chat icon

    – York Shen - MSFT
    Nov 22 '18 at 5:06

















Have you looked at this?

– G.hakim
Nov 21 '18 at 7:44





Have you looked at this?

– G.hakim
Nov 21 '18 at 7:44













I have.. but still no clue where I have to start in my web api.

– Yeremia Danang
Nov 21 '18 at 8:44





I have.. but still no clue where I have to start in my web api.

– Yeremia Danang
Nov 21 '18 at 8:44













You can reach out to App Center support by logging into appcenter.ms/sign-in?original_url=%2Fapps and clicking the chat icon in the lower right corner of the screen. You could get a better support there. :)

– York Shen - MSFT
Nov 22 '18 at 5:05





You can reach out to App Center support by logging into appcenter.ms/sign-in?original_url=%2Fapps and clicking the chat icon in the lower right corner of the screen. You could get a better support there. :)

– York Shen - MSFT
Nov 22 '18 at 5:05













Here's a screenshot if you're having trouble finding the chat icon

– York Shen - MSFT
Nov 22 '18 at 5:06





Here's a screenshot if you're having trouble finding the chat icon

– York Shen - MSFT
Nov 22 '18 at 5:06












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406804%2fhow-to-trigger-app-center-push-from-my-asp-net-web-api%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406804%2fhow-to-trigger-app-center-push-from-my-asp-net-web-api%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy