Exemple #1
0
 public async Task <IActionResult> Post([FromBody] DotThuDTO model)
 {
     using (var context = new UserProfileDbContext())
     {
         context.DotThus.Add(new DotThu
         {
             Id        = model.Id,
             TenDotThu = model.TenDotThu
         });
         //context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[UserProfiles] ON");
         return(Ok(await context.SaveChangesAsync()));
     }
 }
Exemple #2
0
        public async Task <IActionResult> Put(int id, [FromBody] DotThuDTO model)
        {
            using (var context = new UserProfileDbContext())
            {
                var user = await context.DotThus.FirstOrDefaultAsync(x => x.Id.Equals(id));

                if (user == null)
                {
                    return(NotFound());
                }
                user.Id        = model.Id;
                user.TenDotThu = model.TenDotThu;
                return(Ok(await context.SaveChangesAsync()));
            }
        }