Esempio n. 1
0
        public NvVatTuChungTu UpdatePhieu(NvTonDauKyVm.Dto instance)
        {
            var _ParentUnitCode = GetParentUnitCode();

            instance.Calc();
            var exsitItem = FindById(instance.Id);

            if (exsitItem.TrangThai == (int)ApprovalState.IsComplete)
            {
                return(null);
            }
            var masterData            = Mapper.Map <NvTonDauKyVm.Dto, NvVatTuChungTu>(instance);
            var detailData            = Mapper.Map <List <NvTonDauKyVm.DtoDetail>, List <NvVatTuChungTuChiTiet> >(instance.DataDetails);
            var merchandiseCollection = UnitOfWork.Repository <MdMerchandise>().DbSet;

            {
                var detailCollection = UnitOfWork.Repository <NvVatTuChungTuChiTiet>().DbSet.Where(x => x.MaChungTuPk == exsitItem.MaChungTuPk);
                detailCollection.ToList().ForEach(x => x.ObjectState = ObjectState.Deleted);
            }
            detailData.ForEach(x =>
            {
                var merchandise = merchandiseCollection.FirstOrDefault(u => u.MaVatTu == x.MaHang && u.UnitCode.StartsWith(_ParentUnitCode));
                x.TenHang       = merchandise != null ? merchandise.TenHang : "";
                x.Id            = Guid.NewGuid().ToString();
                x.MaChungTuPk   = exsitItem.MaChungTuPk;
                x.MaChungTu     = exsitItem.MaChungTu;
            });
            UnitOfWork.Repository <NvVatTuChungTuChiTiet>().InsertRange(detailData);
            var result = Update(masterData);

            return(result);
        }
Esempio n. 2
0
        public NvVatTuChungTu InsertPhieu(NvTonDauKyVm.Dto instance)
        {
            var _ParentUnitCode = GetParentUnitCode();
            var item            = Mapper.Map <NvTonDauKyVm.Dto, NvVatTuChungTu>(instance);

            item.Id = Guid.NewGuid().ToString();
            var    result    = AddUnit(item);
            string _unitCode = GetCurrentUnitCode();

            result.MaChungTu = BuildCode_PTNX(TypeVoucher.TDK.ToString(), _unitCode, true);
            item.GenerateMaChungTuPk();
            result = Insert(result);
            var merchandiseCollection = UnitOfWork.Repository <MdMerchandise>().DbSet;
            var detailData            = Mapper.Map <List <NvTonDauKyVm.DtoDetail>, List <NvVatTuChungTuChiTiet> >(instance.DataDetails);
            var khoNhap = UnitOfWork.Repository <MdWareHouse>().DbSet.FirstOrDefault(x => x.MaKho == result.MaKhoNhap);

            detailData.ForEach(x => {
                var merchandise = merchandiseCollection.FirstOrDefault(u => u.MaVatTu == x.MaHang && u.UnitCode.StartsWith(_ParentUnitCode));
                x.TenHang       = merchandise != null ? merchandise.TenHang : "";
                x.Id            = Guid.NewGuid().ToString();
                x.MaChungTu     = result.MaChungTu;
                x.MaChungTuPk   = result.MaChungTuPk;
            });
            UnitOfWork.Repository <NvVatTuChungTuChiTiet>().InsertRange(detailData);
            return(result);
        }