Пример #1
0
        public NvDatHang ReceiveSummary(NvPhieuDatHangNCCVm.Dto instance)
        {
            try
            {
                NvDatHang existtItem = FindById(instance.Id);
                if (existtItem.TrangThai == (int)OrderState.IsRecieved)
                {
                    return(null);
                }
                existtItem.TrangThai = (int)OrderState.IsRecieved;
                var result = Update(existtItem);
                instance.DataDetails.ForEach(item =>
                {
                    NvDatHangChiTiet obj = UnitOfWork.Repository <NvDatHangChiTiet>().DbSet.FirstOrDefault(x => x.SoPhieuPk == item.SoPhieuPk && x.MaHang == item.MaHang);
                    if (obj != null)
                    {
                        obj.SoLuongThucTe = item.SoLuongThucTe;
                        obj.ObjectState   = ObjectState.Modified;
                    }
                });

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public NvDatHang UpdatePhieu(NvPhieuDatHangNCCVm.Dto instance)
        {
            instance.Calc();
            var exsitItem = FindById(instance.Id);

            if (exsitItem.TrangThai == (int)OrderState.IsComplete || exsitItem.TrangThai == (int)OrderState.IsRecieved)
            {
                return(null);
            }
            var merchandiseCollection = UnitOfWork.Repository <MdMerchandise>().DbSet;
            var masterData            = Mapper.Map <NvPhieuDatHangNCCVm.Dto, NvDatHang>(instance);
            var detailData            = Mapper.Map <List <NvPhieuDatHangNCCVm.DtoDetail>, List <NvDatHangChiTiet> >(instance.ListEdit);
            {
                var detailCollection = UnitOfWork.Repository <NvDatHangChiTiet>().DbSet.Where(x => x.SoPhieu == exsitItem.SoPhieu);
                detailCollection.ToList().ForEach(x => x.ObjectState = ObjectState.Deleted);
            }
            var result = Update(masterData);

            detailData.ForEach(x =>
            {
                var hang    = merchandiseCollection.FirstOrDefault(u => u.MaVatTu == x.MaHang);
                x.TenHang   = hang != null ? hang.TenHang : "";
                x.Id        = Guid.NewGuid().ToString();
                x.SoPhieu   = exsitItem.SoPhieu;
                x.SoPhieuPk = exsitItem.SoPhieuPk;
                x.MaHd      = masterData.MaHd;
            });
            UnitOfWork.Repository <NvDatHangChiTiet>().InsertRange(detailData);
            return(result);
        }
Пример #3
0
        public NvDatHang InsertPhieu(NvPhieuDatHangNCCVm.Dto instance)
        {
            var item = Mapper.Map <NvPhieuDatHangNCCVm.Dto, NvDatHang>(instance);

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

            result.GenerateMaChungTuPk();
            result.SoPhieu = SaveCode();
            result         = Insert(result);
            var merchandiseCollection = UnitOfWork.Repository <MdMerchandise>().DbSet;
            var dataDetails           = Mapper.Map <List <NvPhieuDatHangNCCVm.DtoDetail>, List <NvDatHangChiTiet> >(instance.ListAdd);

            dataDetails.ForEach(x =>
            {
                var hang    = merchandiseCollection.FirstOrDefault(u => u.MaVatTu == x.MaHang);
                x.TenHang   = hang != null ? hang.TenHang : "";
                x.Id        = Guid.NewGuid().ToString();
                x.SoPhieu   = result.SoPhieu;
                x.SoPhieuPk = result.SoPhieuPk;
                x.MaHd      = result.MaHd;
            });
            UnitOfWork.Repository <NvDatHangChiTiet>().InsertRange(dataDetails);
            return(result);
        }
Пример #4
0
        public NvDatHang InsertSummary(NvPhieuDatHangNCCVm.Dto instance)
        {
            instance.Calc(); //Tinh lại cac thuộc tính thứ sinh

            NvDatHang item = AutoMapper.Mapper.Map <NvPhieuDatHangNCCVm.Dto, NvDatHang>(instance);

            if (!string.IsNullOrEmpty(instance.SoPhieuCon))
            {
                string[] phieus = instance.SoPhieuCon.Split(',');
                if (phieus.Length > 0)
                {
                    item.SoPhieuCon = string.Empty;
                    foreach (var str in phieus)
                    {
                        NvDatHang obj = Repository.DbSet.FirstOrDefault(x => x.SoPhieuPk == str);
                        if (obj != null)
                        {
                            item.SoPhieuCon += obj.SoPhieuPk + ",";
                            obj.TrangThai    = (int)OrderState.IsComplete;
                            obj.ObjectState  = ObjectState.Modified;
                        }
                    }
                }
            }
            item.Id = Guid.NewGuid().ToString();
            NvDatHang result = AddUnit(item);

            result.GenerateMaChungTuPk();
            result.SoPhieu = SaveCode();
            result         = Insert(result);

            DbSet <MdMerchandise> merchandiseCollection     = UnitOfWork.Repository <MdMerchandise>().DbSet;
            List <NvPhieuDatHangNCCVm.DtoDetail> dataFilter = instance.DataDetails.Where(x => x.SoLuong > 0).ToList();
            List <NvDatHangChiTiet> dataDetails             = AutoMapper.Mapper.Map <List <NvPhieuDatHangNCCVm.DtoDetail>, List <NvDatHangChiTiet> >(dataFilter);

            dataDetails.ForEach(x =>
            {
                MdMerchandise hang = merchandiseCollection.FirstOrDefault(u => u.MaVatTu == x.MaHang);
                x.TenHang          = hang != null ? hang.TenHang : "";
                x.Id        = Guid.NewGuid().ToString();
                x.SoPhieu   = result.SoPhieu;
                x.SoPhieuPk = result.SoPhieuPk;
                x.MaHd      = result.MaHd;
            });
            UnitOfWork.Repository <NvDatHangChiTiet>().InsertRange(dataDetails);
            return(result);
        }