public Task <creditorC> GetCreditorSingle(int cr_account_id) { creditorC _obj = null; string _sql = null; try { using (var _db = fnn.GetDbConnection()) { _sql = string.Format("select TOP(1) * from {0} where cr_account_id={1} and delete_id = 0", FleetManager.DbBase.tableNames.creditor_tb.ToDbSchemaTable(), cr_account_id); _obj = _db.Query <creditorC>(_sql).FirstOrDefault(); } } catch (SqlException ex) { LoggerX.LogException(ex); } catch (DbException ex) { LoggerX.LogException(ex); } catch (Exception ex) { LoggerX.LogException(ex); } return(Task.FromResult(_obj)); }
internal static FleetManager.Shared.Models.creditorC CreateCreditor(int cr_owner_id, string cr_owner_name, string phone_no, em.creditor_typeS cr_type, BaseContext _db) { FleetManager.Shared.Models.creditorC _creditor = new creditorC() { created_by_user_id = -1964, cr_account_name = cr_owner_name, cr_account_type_id = cr_type.ToInt32(), cr_owner_id = cr_owner_id, fs_timestamp = fnn.GetUnixTimeStamp(), server_edate = fnn.GetServerDate(), cr_phone_no = phone_no, }; try { _db.CREDITORS_SET.Add(_creditor); var _retVal = _db.SaveChangesWithDuplicateKeyDetected(); if (_retVal == null || _retVal.Value == true) { return(null); } string _sql = null; switch (cr_type) { case em.creditor_typeS.fuel_station: { _sql = string.Format("update {0} set cr_account_id=@v1,fs_timestamp=@v2 where fuel_station_id=@v3 and delete_id=0", FleetManager.DbBase.tableNames.fuel_station_tb.ToDbSchemaTable()); _db.Database.Connection.Execute(_sql, new { v1 = _creditor.cr_account_id, v2 = fnn.GetUnixTimeStamp(), v3 = cr_owner_id }); _db.SaveChanges(); break; } case em.creditor_typeS.mechanic: { _sql = string.Format("update {0} set cr_account_id=@v1,fs_timestamp=@v2 where mechanic_id=@v3 and delete_id=0", FleetManager.DbBase.tableNames.mechanic_tb.ToDbSchemaTable()); _db.Database.Connection.Execute(_sql, new { v1 = _creditor.cr_account_id, v2 = fnn.GetUnixTimeStamp(), v3 = cr_owner_id }); _db.SaveChanges(); break; } case em.creditor_typeS.vehicle_owner: { _sql = string.Format("update {0} set cr_account_id=@v1,fs_timestamp=@v2 where vh_owner_id=@v3 and delete_id=0", FleetManager.DbBase.tableNames.vehicle_owner_tb.ToDbSchemaTable()); _db.Database.Connection.Execute(_sql, new { v1 = _creditor.cr_account_id, v2 = fnn.GetUnixTimeStamp(), v3 = cr_owner_id }); _db.SaveChanges(); break; } } } catch (SqlException ex) { _creditor = null; LoggerX.LogException(ex); } catch (DbException ex) { _creditor = null; LoggerX.LogException(ex); } catch (Exception ex) { _creditor = null; LoggerX.LogException(ex); } return(_creditor); }