예제 #1
0
        public async Task <IHttpActionResult> Post(NvNhapHangBanTraLaiVm.Dto instance)
        {
            TransferObj <NvVatTuChungTu> result = new TransferObj <NvVatTuChungTu>();

            try
            {
                for (int i = 0; i < instance.DataDetails.Count; i++)
                {
                    if (string.IsNullOrEmpty(instance.DataDetails[i].MaHang))
                    {
                        instance.DataDetails.RemoveAt(i);
                    }
                }
                NvVatTuChungTu item = _service.InsertPhieu(instance);
                await _service.UnitOfWork.SaveAsync();

                result.Data   = item;
                result.Status = true;
                return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.Id }, result));
            }
            catch (Exception e)
            {
                return(InternalServerError());
            }
        }
예제 #2
0
        public async Task <IHttpActionResult> GetDetails(string id)
        {
            TransferObj <NvNhapHangBanTraLaiVm.Dto> result = new TransferObj <NvNhapHangBanTraLaiVm.Dto>();

            NvNhapHangBanTraLaiVm.Dto temp = new NvNhapHangBanTraLaiVm.Dto();

            NvVatTuChungTu phieu = _service.FindById(id);

            if (phieu != null)
            {
                temp = Mapper.Map <NvVatTuChungTu, NvNhapHangBanTraLaiVm.Dto>(phieu);
                List <NvVatTuChungTuChiTiet> chiTietPhieu = _service.UnitOfWork.Repository <NvVatTuChungTuChiTiet>().DbSet.Where(x => x.MaChungTuPk == phieu.MaChungTuPk).ToList();
                List <DclGeneralLedger>      chiTietSoCai = _service.UnitOfWork.Repository <DclGeneralLedger>().DbSet.Where(x => x.MaChungTuPk == phieu.MaChungTuPk).ToList();
                temp.DataDetails = Mapper.Map <List <NvVatTuChungTuChiTiet>, List <NvNhapHangBanTraLaiVm.DtoDetail> >(chiTietPhieu);
                //temp.DataDetails.ForEach(x => x.CalcResult());
                temp.DataClauseDetails = Mapper.Map <List <DclGeneralLedger>, List <NvNhapHangBanTraLaiVm.DtoClauseDetail> >(chiTietSoCai);
                result.Data            = temp;
                result.Status          = true;
                return(Ok(result));
            }
            return(NotFound());
        }
예제 #3
0
        public async Task <IHttpActionResult> Put(string id, NvNhapHangBanTraLaiVm.Dto instance)
        {
            TransferObj <NvVatTuChungTu> result = new TransferObj <NvVatTuChungTu>();

            for (int i = 0; i < instance.DataDetails.Count; i++)
            {
                if (instance.DataDetails[i].MaHang == null)
                {
                    instance.DataDetails.RemoveAt(i);
                }
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            NvVatTuChungTu check = _service.FindById(instance.Id);

            if (id != instance.Id || check.TrangThai == (int)ApprovalState.IsComplete)
            {
                return(BadRequest());
            }
            try
            {
                NvVatTuChungTu item = _service.UpdatePhieu(instance);
                await _service.UnitOfWork.SaveAsync();

                result.Status = true;
                result.Data   = item;
                return(Ok(result));
            }
            catch (Exception e)
            {
                return(InternalServerError());
            }
        }