public async Task <IActionResult> Post([FromBody] KhoanThuCoDinhDTO model) { using (var context = new UserProfileDbContext()) { context.KhoanThuCoDinhs.Add(new KhoanThuCoDinh { Id = model.Id, TenKhoanThuCoDinh = model.TenKhoanThuCoDinh, DonGia = model.DonGia, ThuTu = model.ThuTu, GhiChu = model.GhiChu, SuDung = model.SuDung, IdLoaiKhoanThu = model.IdLoaiKhoanThu }); //context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[UserProfiles] ON"); return(Ok(await context.SaveChangesAsync())); } }
public async Task <IActionResult> Put(int id, [FromBody] KhoanThuCoDinhDTO model) { using (var context = new UserProfileDbContext()) { var user = await context.KhoanThuCoDinhs.FirstOrDefaultAsync(x => x.Id.Equals(id)); if (user == null) { return(NotFound()); } user.Id = model.Id; user.TenKhoanThuCoDinh = model.TenKhoanThuCoDinh; user.DonGia = model.DonGia; user.ThuTu = model.ThuTu; user.GhiChu = model.GhiChu; user.SuDung = model.SuDung; user.IdLoaiKhoanThu = model.IdLoaiKhoanThu; return(Ok(await context.SaveChangesAsync())); } }