示例#1
0
        public KHUYENMAI UpdateKhuyenMai(GiamGiaNhaCungCapViewModel.Dto instance)
        {
            var dataKhuyenMai = Mapper.Map <GiamGiaNhaCungCapViewModel.Dto, KHUYENMAI>(instance);

            dataKhuyenMai.I_STATE  = "U";
            dataKhuyenMai.UNITCODE = GetCurrentUnitCode();
            var listProduct = UnitOfWork.Repository <KHUYENMAI_CHITIET>().DbSet.Where(x => x.MA_KHUYENMAI == dataKhuyenMai.MA_KHUYENMAI).ToList();

            if (listProduct.Count > 0)
            {
                listProduct.ForEach(x => x.ObjectState = ObjectState.Deleted);
            }
            List <KHUYENMAI_CHITIET> listDetails = new List <KHUYENMAI_CHITIET>();

            if (instance.DataDetails.Count > 0)
            {
                foreach (var detail in instance.DataDetails)
                {
                    KHUYENMAI_CHITIET khuyenMaiChiTiet = new KHUYENMAI_CHITIET();
                    khuyenMaiChiTiet.ID               = Guid.NewGuid().ToString();
                    khuyenMaiChiTiet.MA_KHUYENMAI     = dataKhuyenMai.MA_KHUYENMAI;
                    khuyenMaiChiTiet.MAHANG           = detail.MANHACUNGCAP;
                    khuyenMaiChiTiet.SOLUONG          = detail.SOLUONG;
                    khuyenMaiChiTiet.GIATRI_KHUYENMAI = detail.GIATRI_KHUYENMAI;
                    khuyenMaiChiTiet.INDEX            = detail.INDEX;
                    listDetails.Add(khuyenMaiChiTiet);
                }
            }
            UnitOfWork.Repository <KHUYENMAI_CHITIET>().InsertRange(listDetails);
            var result = Update(dataKhuyenMai);

            return(result);
        }
示例#2
0
        public KHUYENMAI InsertKhuyenMai(GiamGiaNhaCungCapViewModel.Dto instance)
        {
            var dataKhuyenMai = Mapper.Map <GiamGiaNhaCungCapViewModel.Dto, KHUYENMAI>(instance);

            dataKhuyenMai.ID             = Guid.NewGuid().ToString();
            dataKhuyenMai.LOAI_KHUYENMAI = TypeBuildCode.GGNHACUNGCAP.ToString();
            dataKhuyenMai.THOIGIAN_TAO   = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
            dataKhuyenMai.I_STATE        = "C";
            var result = AddUnit(dataKhuyenMai);
            List <KHUYENMAI_CHITIET> listDetails = new List <KHUYENMAI_CHITIET>();

            if (instance.DataDetails.Count > 0)
            {
                foreach (var detail in instance.DataDetails)
                {
                    KHUYENMAI_CHITIET khuyenMaiChiTiet = new KHUYENMAI_CHITIET();
                    khuyenMaiChiTiet.ID               = Guid.NewGuid().ToString();
                    khuyenMaiChiTiet.MA_KHUYENMAI     = dataKhuyenMai.MA_KHUYENMAI;
                    khuyenMaiChiTiet.MAHANG           = detail.MANHACUNGCAP;
                    khuyenMaiChiTiet.SOLUONG          = detail.SOLUONG;
                    khuyenMaiChiTiet.GIATRI_KHUYENMAI = detail.GIATRI_KHUYENMAI;
                    khuyenMaiChiTiet.INDEX            = detail.INDEX;
                    listDetails.Add(khuyenMaiChiTiet);
                }
            }
            result = Insert(result);
            UnitOfWork.Repository <KHUYENMAI_CHITIET>().InsertRange(listDetails);
            return(result);
        }