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