示例#1
0
        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;
            }));
        }
示例#2
0
        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;
            }));
        }
示例#3
0
        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;
            }));
        }