Пример #1
0
        public NvNgayHetHanHangHoa UpdatePhieu(NvNgayHetHanHangHoaVm.Dto instance)
        {
            string _ParentUnitCode         = GetParentUnitCode();
            string _unitCode               = GetCurrentUnitCode();
            NvNgayHetHanHangHoa exsitItem  = FindById(instance.Id);
            NvNgayHetHanHangHoa masterData = Mapper.Map <NvNgayHetHanHangHoaVm.Dto, NvNgayHetHanHangHoa>(instance);
            List <NvNgayHetHanHangHoaChiTiet>       detailData       = Mapper.Map <List <NvNgayHetHanHangHoaVm.DtoDetail>, List <NvNgayHetHanHangHoaChiTiet> >(instance.DataDetails);
            IQueryable <NvNgayHetHanHangHoaChiTiet> detailCollection = UnitOfWork.Repository <NvNgayHetHanHangHoaChiTiet>().DbSet.Where(x => x.MaPhieuPk == exsitItem.MaPhieuPk);

            detailCollection.ToList().ForEach(x => x.ObjectState = ObjectState.Deleted);
            detailData.ForEach(x =>
            {
                x.Id          = Guid.NewGuid().ToString();
                x.MaPhieuPk   = exsitItem.MaPhieuPk;
                x.IState      = string.Format("{0}", (int)SyncEntityState.IsWaitingForSync);
                x.IUpdateBy   = GetClaimsPrincipal().Identity.Name;
                x.IUpdateDate = DateTime.Now;
                x.UnitCode    = _unitCode;
            });
            masterData.IState      = string.Format("{0}", (int)SyncEntityState.IsWaitingForSync);
            masterData.IUpdateBy   = GetClaimsPrincipal().Identity.Name;
            masterData.IUpdateDate = DateTime.Now;
            masterData.UnitCode    = _unitCode;
            UnitOfWork.Repository <NvNgayHetHanHangHoaChiTiet>().InsertRange(detailData);
            NvNgayHetHanHangHoa result = Update(masterData);

            return(result);
        }
Пример #2
0
        public NvNgayHetHanHangHoa InsertPhieu(NvNgayHetHanHangHoaVm.Dto instance)
        {
            string _ParentUnitCode   = GetParentUnitCode();
            string _unitCode         = GetCurrentUnitCode();
            NvNgayHetHanHangHoa item = Mapper.Map <NvNgayHetHanHangHoaVm.Dto, NvNgayHetHanHangHoa>(instance);

            item.Id = Guid.NewGuid().ToString();
            NvNgayHetHanHangHoa result = AddUnit(item);

            result.MaPhieu = BuildCode_BD("BAODATE", _unitCode, true);
            result.GenerateMaPhieuPk();
            result.TrangThai = 10;
            result           = Insert(result);
            List <NvNgayHetHanHangHoaChiTiet> detailData = Mapper.Map <List <NvNgayHetHanHangHoaVm.DtoDetail>, List <NvNgayHetHanHangHoaChiTiet> >(instance.DataDetails);

            detailData.ForEach(x =>
            {
                x.Id          = Guid.NewGuid().ToString();
                x.MaPhieuPk   = result.MaPhieuPk;
                x.IState      = string.Format("{0}", (int)SyncEntityState.IsWaitingForSync);
                x.ICreateBy   = GetClaimsPrincipal().Identity.Name;
                x.ICreateDate = DateTime.Now;
            });
            item.IState      = string.Format("{0}", (int)SyncEntityState.IsWaitingForSync);
            item.ICreateBy   = GetClaimsPrincipal().Identity.Name;
            item.ICreateDate = DateTime.Now;
            UnitOfWork.Repository <NvNgayHetHanHangHoaChiTiet>().InsertRange(detailData);
            return(result);
        }