public async Task <ActionResultDto> Execute(ContextDto context) { try { init(); validate(); // TODO load chi tiêt var bizGetListChiTiet = new GetListChiTietByPhieuNhapIdBiz(context); bizGetListChiTiet.PHIEU_NHAP_ID = _phieuNhapId; bizGetListChiTiet.LOGIN_ID = _LoginId; var listChiTiet = await bizGetListChiTiet.Execute(); if (listChiTiet.Count() < 1) { throw new BaseException("Không tìm thấy thông tin chi tết"); } var affected = 0; var biz = new LuuSoCaiBiz(context); foreach (var chitiet in listChiTiet) { biz.PHIEU_NHAP_CHI_TIET_ID = chitiet.PhieuNhapChiTietId; var result = await biz.Execute(); if (result.Count() > 0 && string.IsNullOrEmpty(biz.MESSAGE)) { affected = affected + 1; } else { throw new BaseException(biz.MESSAGE.Split('|')[2]); } } // TODO đổi trang thai phiếu nhập var repoPhieuNhap = new KhoPhieuNhapRepository(context); var phieunhap = new Entity.MSSQL_QLDN_QLNS.Entity.KhoPhieuNhap(); phieunhap.PhieuNhapId = _phieuNhapId; phieunhap.MaTrangThai = "KPN_LSC"; var resultUpdatePhieuNhap = await repoPhieuNhap.UpdatePartial(phieunhap , nameof(phieunhap.MaTrangThai)); var ls = new InsertKhoLuocSuAction(); ls.InsertKhoLuocSu(context, "KhoPhieuNhap", _phieuNhapId, "Update", _LoginId); dynamic _metaData = new System.Dynamic.ExpandoObject(); return(ActionHelper.returnActionResult(HttpStatusCode.OK, resultUpdatePhieuNhap, _metaData)); } catch (BaseException ex) { return(ActionHelper.returnActionError(HttpStatusCode.BadRequest, ex.Message)); } catch (Exception ex) { return(ActionHelper.returnActionError(HttpStatusCode.InternalServerError, ex.InnerException != null ? ex.InnerException.Message : ex.Message)); } }
/// <summary> /// Ham xu ly chinh, chi nhan 1 bien moi truong /// </summary> /// <param name="context">Bien moi truong</param> /// <returns></returns> public async Task <dynamic> Execute() { Init(); Validate(); // to do: // biz se thuc hien viec abc o day truoc khi goi dac PhieuNhap.XoaYN = "N"; PhieuNhap.CtrVersion = 1; var repo = new KhoPhieuNhapRepository(_context); var result = await repo.Insert(PhieuNhap); if (ListChiTiet == null || ListChiTiet.Count == 0) { return(result); } var repoChiTiet = new KhoPhieuNhapChiTietRepository(_context); foreach (var item in ListChiTiet) { item.PhieuNhapId = result.PhieuNhapId; item.XoaYN = "N"; item.CtrVersion = 1; await repoChiTiet.Insert(item); } // goi lai ham execute cua tang dac // to do: // biz se thuc hien viec abc voi result truoc khi return return(result); }