public async Task <IHttpActionResult> GetDetails(string id) { var result = new TransferObj <NvNhapKhacVm.Dto>(); var temp = new NvNhapKhacVm.Dto(); var _ParentUnitCode = _service.GetParentUnitCode(); var phieu = _service.FindById(id); if (phieu != null) { temp = Mapper.Map <NvVatTuChungTu, NvNhapKhacVm.Dto>(phieu); var chiTietPhieu = _service.UnitOfWork.Repository <NvVatTuChungTuChiTiet>().DbSet.Where(x => x.MaChungTuPk == phieu.MaChungTuPk).ToList(); temp.DataDetails = Mapper.Map <List <NvVatTuChungTuChiTiet>, List <NvNhapKhacVm.DtoDetail> >(chiTietPhieu); string unitcode = _service.GetCurrentUnitCode(); foreach (NvNhapKhacVm.DtoDetail dt in temp.DataDetails) { var sp = _service.UnitOfWork.Repository <MdMerchandisePrice>().DbSet.Where(x => x.MaVatTu.Equals(dt.MaHang) && x.MaDonVi.StartsWith(_ParentUnitCode)).FirstOrDefault(); var item = _service.UnitOfWork.Repository <MdMerchandise>().DbSet.Where(x => x.MaVatTu.Equals(dt.MaHang) && x.UnitCode.StartsWith(_ParentUnitCode)).FirstOrDefault(); if (sp != null) { dt.TyLeVatVao = sp.TyLeVatVao; } if (item != null) { dt.TenHang = item.TenHang; } } result.Data = temp; result.Status = true; return(Ok(result)); } return(NotFound()); }
public async Task <IHttpActionResult> Put(string id, NvNhapKhacVm.Dto instance) { var result = new TransferObj <NvVatTuChungTu>(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var check = _service.FindById(instance.Id); if (id != instance.Id || check.TrangThai == (int)ApprovalState.IsComplete) { return(BadRequest()); } try { var item = _service.UpdatePhieu(instance); await _service.UnitOfWork.SaveAsync(); result.Status = true; result.Data = item; return(Ok(result)); } catch (Exception e) { return(InternalServerError()); } }
public async Task <IHttpActionResult> PostXuLyHangAm(NvNhapKhacVm.Dto instance) { var result = new TransferObj <NvVatTuChungTu>(); try { if (_service.ValidateNgayCT(instance.NgayCT.Value)) { var item = _service.InsertPhieuXuLyAm(instance); await _service.UnitOfWork.SaveAsync(); result.Data = item; result.Status = true; return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.Id }, result)); } return(InternalServerError()); } catch (Exception e) { return(InternalServerError()); } }