Esempio n. 1
0
        public async Task <KhoNuocSanXuat> UpdatePartial(KhoNuocSanXuat nuocsx, params string[] field)
        {
            var a = await WithConnection(async c =>
            {
                KhoNuocSanXuat obj = await c.GetAsync(nuocsx);

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

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

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

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

                return(nuocsx);
            });

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

                if (nuocsx.NuocSanXuatId == 0)
                {
                    throw new Exception("Insert Fail");
                }

                return nuocsx;
            }));
        }
Esempio n. 3
0
        public async Task <KhoNuocSanXuat> Update(KhoNuocSanXuat nuocsx)
        {
            return(await WithConnection(async c =>
            {
                KhoNuocSanXuat obj = await c.GetAsync(nuocsx);

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

                var result = await c.UpdateAsync(nuocsx);

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

                return nuocsx;
            }));
        }