예제 #1
0
        public async Task <KhoPhieuNhap> UpdatePartial(KhoPhieuNhap kho, params string[] field)
        {
            var a = await WithConnection(async c =>
            {
                var obj = await c.GetAsync(kho);

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

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

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

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

                return(kho);
            });

            return(a);
        }
예제 #2
0
        public async Task <KhoPhieuNhap> Insert(KhoPhieuNhap kho)
        {
            kho.XoaYN    = "N";
            kho.NgayTao  = kho.NgayTao ?? DateTime.Now;
            kho.NguoiTao = kho.NguoiTao ?? null;
            return(await WithConnection(async c =>
            {
                await c.InsertAsync(kho);

                if (kho.PhieuNhapId == 0)
                {
                    throw new Exception("Insert Fail");
                }

                return kho;
            }));
        }
예제 #3
0
        public async Task <KhoPhieuNhap> Update(KhoPhieuNhap kho)
        {
            return(await WithConnection(async c =>
            {
                var obj = await c.GetAsync(kho);

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

                var result = await c.UpdateAsync(kho);

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

                return kho;
            }));
        }