public async Task <IActionResult> Add([FromBody] Khutrochoi model)
        {
            if (ModelState.IsValid)
            {
                //1. business logic

                //data validation
                if (model.TenKhu.Length == 0)
                {
                    return(BadRequest());
                }
                //2. add new object
                try
                {
                    var newObj = await repository.Add(model);

                    if (newObj.MaKhu != null)
                    {
                        var novaticResponse = NovaResponse.CREATED(model);
                        return(Created("", novaticResponse));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception)
                {
                    return(BadRequest());
                }
            }
            return(BadRequest());
        }
        public async Task <IActionResult> Delete([FromBody] Khutrochoi model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //1. business logic
                    //set Active to 0

                    //2. logically delete object
                    await repository.Delete(model.MaKhu);

                    var novaticResponse = NovaResponse.SUCCESS(model);
                    return(Ok(novaticResponse));
                }
                catch (Exception ex)
                {
                    if (ex.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException")
                    {
                        return(NotFound());
                    }

                    return(BadRequest());
                }
            }
            return(BadRequest());
        }
        public async Task <Khutrochoi> Add(Khutrochoi obj)
        {
            if (db != null)
            {
                await db.Khutrochois.AddAsync(obj);

                await db.SaveChangesAsync();

                return(obj);
            }

            return(null);
        }
 public async Task Update(Khutrochoi obj)
 {
     if (db != null)
     {
         //Update that object
         db.Khutrochois.Attach(obj);
         // db.Entry(obj).Property(x => x.Name).IsModified = true;
         // db.Entry(obj).Property(x => x.Description).IsModified = true;
         // db.Entry(obj).Property(x => x.Active).IsModified = true;
         db.Entry(obj).Property(x => x.MaKhu).IsModified         = true;
         db.Entry(obj).Property(x => x.TenKhu).IsModified        = true;
         db.Entry(obj).Property(x => x.MaNvql).IsModified        = true;
         db.Entry(obj).Property(x => x.GiaVeTreEm).IsModified    = true;
         db.Entry(obj).Property(x => x.GiaVeNguoiLon).IsModified = true;
         //Commit the transaction
         await db.SaveChangesAsync();
     }
 }