manpreet gill

manpreet gill

  • NA
  • 4
  • 1.1k

return value in post method using async Task(C# And Mongodb)

Feb 9 2018 7:50 AM
 
Controller  
// POST api/values
[HttpPost]
public void Post([FromBody]TicketsModel Value)
{

_ticketsRepository.AddTickets(new TicketsModel()
{
 
Source = Value.Source,
key = Value.any,
});
}
 service
// add new note document
Task AddTickets(TicketsModel item);  
 
 
function 
// add new note document
public async Task AddTickets(TicketsModel item)
{
var data = "";

try
{
// Added Filter to Check Duplicate records on Bases of TicketId
// var query = Builders<TicketsModel>.Filter.Eq(s => s.TicketId, item.TicketId);
var results = _context.Tickets.Find(x => x.TicketId == item.TicketId).Count();

//if it is 0 then only we are going to insert document
if (results == 0)
{
await _context.Tickets.InsertOneAsync(item);
}
else
{

data = "Carname ALready Exist";
}
//return data;

}
catch (Exception ex)
{
// log or manage the exception
throw ex;
}
}  

Answers (1)