10 TIPs - To Become a Good Developer/Programmer
Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
manpreet gill
2.1k
4
775
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
;
}
}
Reply
Answers (
1
)
Saving Selected Checkbox in database using MVC
Methods in C Sharp