public async Task <LoaiNghiPhep> Update(LoaiNghiPhep entity) { return(await WithConnection(async c => { LoaiNghiPhep obj = await c.GetAsync(entity); if (obj == null) { throw new Exception(string.Format("Update id {0} not exist", entity.LoaiNghiPhepId.ToString())); } if (obj.CtrVersion != entity.CtrVersion) { throw new Exception(string.Format("Update id {0} have version confict" , entity.LoaiNghiPhepId.ToString())); } entity.CtrVersion += 1; var result = await c.UpdateAsync(entity); if (result != true) { throw new Exception("Update Fail"); } return entity; })); }
public async Task <LoaiNghiPhep> Insert(LoaiNghiPhep entity) { return(await WithConnection(async c => { await c.InsertAsync(entity); if (entity.LoaiNghiPhepId == 0) { throw new Exception("Insert Fail"); } return entity; })); }
public async Task <LoaiNghiPhep> UpdatePartial(LoaiNghiPhep entity, params string[] field) { return(await WithConnection(async c => { LoaiNghiPhep obj = await c.GetAsync(entity); if (obj == null) { throw new Exception(string.Format("Update id {0} not exist", entity.LoaiNghiPhepId.ToString())); } if (obj.CtrVersion != entity.CtrVersion) { throw new Exception(string.Format("Update id {0} have version confict" , entity.LoaiNghiPhepId.ToString())); } entity.CtrVersion += 1; var list = field.ToList(); list.Add(nameof(LoaiNghiPhep.CtrVersion)); var partialUpdateMapping = OrmConfiguration .GetDefaultEntityMapping <LoaiNghiPhep>() .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; })); }