Esempio n. 1
0
        public MdBoHang UpdateDto(MdBoHangVm.Dto instance)
        {
            MdBoHang result = null;
            var      item   = FindById(instance.Id);

            if (item != null)
            {
                result = Update(Mapper.Map <MdBoHangVm.Dto, MdBoHang>(instance));
                {//delete
                    var deleteList = UnitOfWork.Repository <MdBoHangChiTiet>().DbSet.Where(x => x.MaBoHang == result.MaBoHang).ToList();
                    deleteList.ForEach(x => x.ObjectState = ObjectState.Deleted);
                }
                {//insert data details
                    var merchandiseCollection = UnitOfWork.Repository <MdBoHangChiTiet>().DbSet;
                    var detail = Mapper.Map <List <MdBoHangVm.DtoDetail>, List <MdBoHangChiTiet> >(instance.DataDetails);
                    detail.ForEach(x =>
                    {
                        var hang   = merchandiseCollection.FirstOrDefault(u => u.MaHang == x.MaHang);
                        x.Id       = Guid.NewGuid().ToString();
                        x.MaBoHang = result.MaBoHang;
                    });
                    UnitOfWork.Repository <MdBoHangChiTiet>().InsertRange(detail);
                }
            }
            return(result);
        }
Esempio n. 2
0
        public MdBoHang InsertDto(MdBoHangVm.Dto instance)
        {
            var item = AutoMapper.Mapper.Map <MdBoHangVm.Dto, MdBoHang>(instance);

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

            result = Insert(result);
            var detail = Mapper.Map <List <MdBoHangVm.DtoDetail>, List <MdBoHangChiTiet> >(instance.DataDetails);
            var merchandiseCollection = UnitOfWork.Repository <MdMerchandise>().DbSet;

            detail.ForEach(x => {
                var hang   = merchandiseCollection.FirstOrDefault(u => u.MaVatTu == x.MaHang);
                x.Id       = Guid.NewGuid().ToString();
                x.MaBoHang = result.MaBoHang;
            });
            UnitOfWork.Repository <MdBoHangChiTiet>().InsertRange(detail);

            return(result);
        }