/// <summary> /// Insert MR /// </summary> /// <param name="pObj"></param> /// <param name="pTransBy"></param> public void Insert(IList <MR> pObj, string pTransBy, long pPreparedBy) { try { using (var _con = new SqlConnection(FixedAssets.Context)) { _con.Open(); using (var _tran = _con.BeginTransaction()) { try { foreach (var _item in pObj) { _item.Remarks = string.Empty; _item.PreparedBy = pPreparedBy; if (_item.EmployeeId.Equals(0)) { throw new Exception("EmployeeId is zero"); } else if (_item.AssetItemId.Equals(0)) { throw new Exception("AssetItemId is zero"); } else if (string.IsNullOrEmpty(pTransBy)) { throw new Exception("Transaction By is null or empty"); } else if (pPreparedBy.Equals(0)) { throw new Exception("Prepared By is null or empty"); } lIMRs.Insert(_item.EmployeeId, _item.AssetItemId, pPreparedBy, pTransBy, _tran); lIAssetsItems.Update(_item.AssetItemId, AssetStatus.Assigned.ToString(), _item.Remarks, pTransBy, _tran); } _tran.Commit(); } catch (Exception ex) { _tran.Rollback(); throw ex; } } } } catch (Exception ex) { throw ex; } }
/// <summary> /// Update assets items /// </summary> /// <param name="pObj">Entity</param> /// <param name="pTransBy">Transact By</param> public void Update(IList <AssetItem> pObj, string pTransBy) { try { using (var _con = new SqlConnection(FixedAssets.Context)) { _con.Open(); using (var _tran = _con.BeginTransaction()) { try { foreach (var _obj in pObj) { if (_obj.AssetItemId.Equals(0)) { throw new Exception("Asset Item ID is zero"); } else if (string.IsNullOrEmpty(_obj.AssetGroup)) { throw new Exception("Asset Group is empty or null"); } else if (string.IsNullOrEmpty(_obj.AssetCode)) { throw new Exception("Asset Code is empty or null"); } else if (string.IsNullOrEmpty(_obj.AssetName)) { throw new Exception("Asset Name is empty or null"); } else if (string.IsNullOrEmpty(_obj.AssetType)) { throw new Exception("Asset Type is empty or null"); } else if (_obj.UnitCost.Equals(0)) { throw new Exception("Unit Cost is zero"); } else if (string.IsNullOrEmpty(_obj.SerialNumber)) { throw new Exception("Serial Number is empty or null"); } else if (_obj.UsefulLife.Equals(0)) { throw new Exception("Useful Life is zero"); } else if (_obj.ServiceDate.Date.Equals(DefaultValue.datetime.Date)) { throw new Exception("Date Service is null or below 1754/1/1"); } else if (string.IsNullOrEmpty(pTransBy)) { throw new Exception("Transaction By is empty or null"); } lIAssetsItems.Update(_obj, pTransBy, _tran); } _tran.Commit(); } catch (Exception ex) { _tran.Rollback(); throw ex; } } } } catch (Exception ex) { throw ex; } }