public async Task <IHttpActionResult> GetChild(string id) { TransferObj <List <NvDatHang> > result = new TransferObj <List <NvDatHang> >(); List <NvDatHang> temp = new List <NvDatHang>(); NvDatHang phieu = _service.FindById(id); if (phieu != null) { if (!string.IsNullOrEmpty(phieu.SoPhieuCon)) { string[] phieus = phieu.SoPhieuCon.Split(','); if (phieus.Length > 0) { foreach (var str in phieus) { NvDatHang obj = _service.UnitOfWork.Repository <NvDatHang>().DbSet.FirstOrDefault(x => x.SoPhieuPk == str); if (obj != null) { temp.Add(obj); } } } } result.Data = temp; result.Status = true; return(Ok(result)); } return(NotFound()); }
public async Task <IHttpActionResult> Put(string id, NvPhieuDatHangNCCVm.Dto instance) { var result = new TransferObj <NvDatHang>(); NvDatHang check = _service.FindById(instance.Id); if (id != instance.Id || check.TrangThai == (int)ApprovalState.IsComplete) { return(BadRequest()); } if (check == null) { return(NotFound()); } try { var item = _service.UpdatePhieu(instance); _service.UnitOfWork.Save(); result.Status = true; result.Data = item; return(Ok(result)); } catch (Exception e) { return(InternalServerError()); } }
public async Task <IHttpActionResult> PostReceiveSummary(NvPhieuDatHangNCCVm.Dto instance) { TransferObj <NvDatHang> result = new TransferObj <NvDatHang>(); try { NvDatHang item = _service.ReceiveSummary(instance); _service.UnitOfWork.Save(); result.Data = item; result.Status = true; return(Ok(result)); } catch (Exception e) { result.Status = false; result.Message = e.Message; return(Ok(result)); } }
public async Task <IHttpActionResult> PostAddNewSummary(NvPhieuDatHangNCCVm.Dto instance) { TransferObj <NvDatHang> result = new TransferObj <NvDatHang>(); try { NvDatHang item = _service.InsertSummary(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)); } }
public async Task <IHttpActionResult> PostDeleteSummary(NvDatHang item) { NvDatHang instance = await _service.Repository.FindAsync(item.Id); if (instance == null) { return(NotFound()); } try { _service.DeleteSummary(instance); await _service.UnitOfWork.SaveAsync(); return(Ok(instance)); } catch (Exception) { return(InternalServerError()); } }
public async Task <IHttpActionResult> Delete(string id) { NvDatHang instance = await _service.Repository.FindAsync(id); if (instance == null) { return(NotFound()); } try { if (_service.DeletePhieu(id)) { _service.Delete(instance.Id); _service.UnitOfWork.Save(); return(Ok(instance)); } return(InternalServerError()); } catch (Exception e) { WriteLogs.LogError(e); return(InternalServerError()); } }
public List <IQueryFilter> GetFilters() { var result = new List <IQueryFilter>(); var refObj = new NvDatHang(); if (TrangThai.HasValue) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.TrangThai), Value = this.TrangThai.Value, Method = FilterMethod.EqualTo }); } if (!string.IsNullOrEmpty(this.UnitCode)) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.UnitCode), Value = this.UnitCode, Method = FilterMethod.EqualTo }); } if (!string.IsNullOrEmpty(this.MaHd)) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.MaHd), Value = this.MaHd, Method = FilterMethod.Like }); } if (!string.IsNullOrEmpty(this.NoiDung)) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.NoiDung), Value = this.NoiDung, Method = FilterMethod.Like }); } if (!string.IsNullOrEmpty(this.NguoiLap)) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.NguoiLap), Value = this.NguoiLap, Method = FilterMethod.Like }); } if (!string.IsNullOrEmpty(this.SoPhieu)) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.SoPhieu), Value = this.SoPhieu, Method = FilterMethod.Like }); } if (this.TuNgay.HasValue) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.Ngay), Value = this.TuNgay.Value, Method = FilterMethod.GreaterThanOrEqualTo }); } if (this.DenNgay.HasValue) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.Ngay), Value = this.DenNgay.Value.AddDays(1), Method = FilterMethod.LessThan }); } return(result); }