Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Put(string id, NvKhuyenMaiBuy1Get1Vm.Dto instance)
        {
            TransferObj <NvChuongTrinhKhuyenMai> result = new TransferObj <NvChuongTrinhKhuyenMai>();
            NvChuongTrinhKhuyenMai check = _service.FindById(instance.Id);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (check == null)
            {
                return(NotFound());
            }
            try
            {
                NvChuongTrinhKhuyenMai item = _service.UpdatePhieu(instance);
                _service.UnitOfWork.Save();
                result.Status = true;
                result.Data   = item;
                return(Ok(result));
            }
            catch (Exception e)
            {
                return(InternalServerError());
            }
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> Post(NvKhuyenMaiBuy1Get1Vm.Dto instance)
        {
            TransferObj <NvChuongTrinhKhuyenMai> result = new TransferObj <NvChuongTrinhKhuyenMai>();

            try
            {
                NvChuongTrinhKhuyenMai item = _service.InsertPhieu(instance);
                _service.UnitOfWork.Save();
                result.Data   = item;
                result.Status = true;
                return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.Id }, result));
            }
            catch (Exception e)
            {
                result.Status  = false;
                result.Message = e.Message;
                return(Ok(result));
            }
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> GetDetails(string id)
        {
            var result = new TransferObj <NvKhuyenMaiBuy1Get1Vm.Dto>();
            var temp   = new NvKhuyenMaiBuy1Get1Vm.Dto();

            var phieu = _service.FindById(id);

            if (phieu != null)
            {
                temp = Mapper.Map <NvChuongTrinhKhuyenMai, NvKhuyenMaiBuy1Get1Vm.Dto>(phieu);
                var tb_ChuongTrinhKhuyenMaiChiTiet = _service.UnitOfWork.Repository <NvChuongTrinhKhuyenMaiChiTiet>().DbSet;

                var chiTietChuongTrinhKhuyenMai = tb_ChuongTrinhKhuyenMaiChiTiet.Where(x => x.MaChuongTrinh == phieu.MaChuongTrinh).ToList();
                temp.DataDetails = Mapper.Map <List <NvChuongTrinhKhuyenMaiChiTiet>, List <NvKhuyenMaiBuy1Get1Vm.DtoDetail> >(chiTietChuongTrinhKhuyenMai);
                //var dataGift = _service.UnitOfWork.Repository<NvChuongTrinhKhuyenMaiHangKM>().DbSet.Where(x => x.MaChuongTrinh == phieu.MaChuongTrinh).ToList();
                //temp.DataGifts = Mapper.Map<List<NvChuongTrinhKhuyenMaiHangKM>, List<NvKhuyenMaiBuy1Get1Vm.DtoDetail>>(dataGift);
                result.Data   = temp;
                result.Status = true;
                return(Ok(result));
            }
            return(NotFound());
        }