Ejemplo n.º 1
0
        public BOHANG UpdateBohang(BoHangViewModel.Dto instance)
        {
            var dataBoHang = Mapper.Map <BoHangViewModel.Dto, BOHANG>(instance);

            dataBoHang.I_STATE = "U";
            var listBoHangChiTiet = UnitOfWork.Repository <BOHANG_CHITIET>().DbSet.Where(x => x.MABOHANG == dataBoHang.MABOHANG).ToList();

            if (listBoHangChiTiet.Count > 0)
            {
                listBoHangChiTiet.ForEach(x => x.ObjectState = ObjectState.Deleted);
            }
            var dataDetails = Mapper.Map <List <BoHangViewModel.DataDetails>, List <BOHANG_CHITIET> >(instance.DataDetails);

            dataDetails.ForEach(x =>
            {
                x.ID            = Guid.NewGuid().ToString();
                x.MABOHANG      = dataBoHang.MABOHANG;
                x.I_CREATE_DATE = DateTime.Now;
                x.I_CREATE_BY   = dataBoHang.I_CREATE_BY;
                x.I_STATE       = dataBoHang.I_STATE;
                x.UNITCODE      = dataBoHang.UNITCODE;
            });
            UnitOfWork.Repository <BOHANG_CHITIET>().InsertRange(dataDetails);
            var result = Update(dataBoHang);

            return(result);
        }
Ejemplo n.º 2
0
        public BOHANG InsertBohang(BoHangViewModel.Dto instance)
        {
            var dataBoHang = Mapper.Map <BoHangViewModel.Dto, BOHANG>(instance);

            dataBoHang.ID      = Guid.NewGuid().ToString();
            dataBoHang.I_STATE = "C";
            var result      = AddUnit(dataBoHang);
            var dataDetails = Mapper.Map <List <BoHangViewModel.DataDetails>, List <BOHANG_CHITIET> >(instance.DataDetails);

            result = Insert(result);
            dataDetails.ForEach(x =>
            {
                x.ID            = Guid.NewGuid().ToString();
                x.MABOHANG      = result.MABOHANG;
                x.I_CREATE_DATE = DateTime.Now;
                x.I_CREATE_BY   = result.I_CREATE_BY;
                x.I_STATE       = result.I_STATE;
                x.UNITCODE      = result.UNITCODE;
            });
            UnitOfWork.Repository <BOHANG_CHITIET>().InsertRange(dataDetails);
            return(result);
        }