public async Task <KhoNhomHangHoa> UpdatePartial(KhoNhomHangHoa nuocsx, params string[] field) { var a = await WithConnection(async c => { KhoNhomHangHoa obj = await c.GetAsync(nuocsx); if (obj == null) { throw new Exception(string.Format("Update id {0} not exist", nuocsx.NhomHangHoaId.ToString())); } var list = field.ToList(); var partialUpdateMapping = OrmConfiguration .GetDefaultEntityMapping <KhoNhomHangHoa>() .Clone() .UpdatePropertiesExcluding(prop => prop.IsExcludedFromUpdates = true, list.ToArray()); var result = await c.UpdateAsync(nuocsx, statement => statement.WithEntityMappingOverride(partialUpdateMapping)); if (result != true) { throw new Exception("Update Fail"); } return(nuocsx); }); return(a); }
public async Task <KhoNhomHangHoa> Insert(KhoNhomHangHoa nuocsx) { return(await WithConnection(async c => { await c.InsertAsync(nuocsx); if (nuocsx.NhomHangHoaId == 0) { throw new Exception("Insert Fail"); } return nuocsx; })); }
public async Task <KhoNhomHangHoa> Update(KhoNhomHangHoa nuocsx) { return(await WithConnection(async c => { KhoNhomHangHoa obj = await c.GetAsync(nuocsx); if (obj == null) { throw new Exception(string.Format("Update id {0} not exist", nuocsx.NhomHangHoaId.ToString())); } var result = await c.UpdateAsync(nuocsx); if (result != true) { throw new Exception("Update Fail"); } return nuocsx; })); }