public async Task <QuanLyHopDong> Update(QuanLyHopDong model) { return(await WithConnection(async c => { var obj = await c.GetAsync(model); if (obj == null) { throw new Exception(string.Format("Update id {0} not exist", model.QuanLyHopDongId.ToString())); } if (obj.CtrVersion != model.CtrVersion) { throw new Exception(string.Format("Update id {0} have version confict" , model.QuanLyHopDongId.ToString())); } model.CtrVersion += 1; var result = await c.UpdateAsync(model); if (result != true) { throw new Exception("Update Fail"); } return model; })); }
public async Task <QuanLyHopDong> Insert(QuanLyHopDong obj) { return(await WithConnection(async c => { await c.InsertAsync(obj); if (obj.QuanLyHopDongId == 0) { throw new Exception("Insert Fail"); } return obj; })); }
public async Task <QuanLyHopDong> UpdatePartialBase(QuanLyHopDong model, bool checkCtrVersion, params string[] field) { return(await WithConnection(async c => { var obj = await c.GetAsync(model); if (obj == null) { throw new Exception(string.Format("Update id {0} not exist", model.QuanLyHopDongId.ToString())); } if (checkCtrVersion == true && obj.CtrVersion != model.CtrVersion) { throw new Exception(string.Format("Update id {0} have version confict" , model.QuanLyHopDongId.ToString())); } model.CtrVersion += 1; var list = field.ToList(); list.Add(nameof(QuanLyHopDong.CtrVersion)); var partialUpdateMapping = OrmConfiguration .GetDefaultEntityMapping <QuanLyHopDong>() .Clone() // clone it if you don't want to modify the default .UpdatePropertiesExcluding(prop => prop.IsExcludedFromUpdates = true, list.ToArray()); var result = await c.UpdateAsync(model, statement => statement.WithEntityMappingOverride(partialUpdateMapping)); if (result != true) { throw new Exception("Update Fail"); } return model; })); }
public async Task <QuanLyHopDong> UpdatePartial(QuanLyHopDong model, params string[] field) { return(await UpdatePartialBase(model, true, field)); }