我对POST的Web服务有点新,我想保存我从Owin获得的userId和最喜欢的表中的id_cd。下面发布的web服务正在运行,但是我不需要返回返回UserProvider。不需要整个ListAspNetUserLogins ...等部分,但我似乎找不到允许我添加两个变量的POST。我需要改变什么仍然有两个变量进来并摆脱返回UserProvider等。
[Route("api/User/PostUserFavorite/{id_cd}/{UserId}")]
public async Task<List<AspNetUserLogins>> PostUserFavorite(int id_cd, string UserId)
{
User_FavoriteCd newEntry = new User_FavoriteCd();
newEntry.id_id = id_cd;
newEntry.datetime = DateTime.Now;
newEntry.UserId = UserId;
db.User_FavoriteCd.Add(newEntry);
db.SaveChanges();
List<AspNetUserLogins> UserProvider = await db.AspNetUserLogins
.Where(up => up.UserId == UserId)
.ToListAsync();
return UserProvider;
}
答案 0 :(得分:1)
如果您不需要返回值,则可以执行以下操作:
[Route("api/User/PostUserFavorite/{id_cd}/{UserId}")]
public async Task PostUserFavorite(int id_cd, string UserId)
{
User_FavoriteCd newEntry = new User_FavoriteCd();
newEntry.id_id = id_cd;
newEntry.datetime = DateTime.Now;
newEntry.UserId = UserId;
db.User_FavoriteCd.Add(newEntry);
await db.SaveChangesAsync();
}