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