Esempio n. 1
0
        public async Task <KhenThuongCaNhan> Update(KhenThuongCaNhan khenthuong)
        {
            return(await WithConnection(async c =>
            {
                KhenThuongCaNhan obj = await c.GetAsync(khenthuong);

                if (obj == null)
                {
                    throw new Exception(string.Format("Update id {0} not exist", khenthuong.KhenThuongCaNhanId.ToString()));
                }

                if (obj.CtrVersion != khenthuong.CtrVersion)
                {
                    throw new Exception(string.Format("Update id {0} have version confict"
                                                      , khenthuong.KhenThuongCaNhanId.ToString()));
                }

                khenthuong.CtrVersion += 1;

                var result = await c.UpdateAsync(khenthuong);

                if (result != true)
                {
                    throw new Exception("Update Fail");
                }

                return khenthuong;
            }));
        }
Esempio n. 2
0
        public async Task <KhenThuongCaNhan> Insert(KhenThuongCaNhan khenthuong)
        {
            return(await WithConnection(async c =>
            {
                await c.InsertAsync(khenthuong);

                if (khenthuong.KhenThuongCaNhanId == 0)
                {
                    throw new Exception("Insert Fail");
                }

                return khenthuong;
            }));
        }
Esempio n. 3
0
        public async Task <KhenThuongCaNhan> UpdatePartial(KhenThuongCaNhan khenthuong, params string[] field)
        {
            var a = await WithConnection(async c =>
            {
                KhenThuongCaNhan obj = await c.GetAsync(khenthuong);

                if (obj == null)
                {
                    throw new Exception(string.Format("Update id {0} not exist", khenthuong.KhenThuongCaNhanId.ToString()));
                }

                if (obj.CtrVersion != khenthuong.CtrVersion)
                {
                    throw new Exception(string.Format("Update id {0} have version confict"
                                                      , khenthuong.KhenThuongCaNhanId.ToString()));
                }

                khenthuong.CtrVersion += 1;
                var list = field.ToList();

                list.Add(nameof(khenthuong.CtrVersion));

                var partialUpdateMapping = OrmConfiguration
                                           .GetDefaultEntityMapping <KhenThuongCaNhan>()
                                           .Clone()
                                           .UpdatePropertiesExcluding(prop => prop.IsExcludedFromUpdates = true,
                                                                      list.ToArray());

                var result = await c.UpdateAsync(khenthuong, statement => statement.WithEntityMappingOverride(partialUpdateMapping));

                if (result != true)
                {
                    throw new Exception("Update Fail");
                }

                return(khenthuong);
            });

            return(a);
        }