public IActionResult OnPostAdd(int id) { var supplierMapping = new SupplierMapping { SupplierId = id, AccountId = ManagerId }; _mappingRepo.Insert(supplierMapping); return(RedirectToPage()); }
public IActionResult OnGetRemove(int id, int managerId) { var supplierMapping = new SupplierMapping { SupplierId = id, AccountId = managerId }; _mappingRepo.Remove(supplierMapping); return(RedirectToPage()); }
public bool Remove(SupplierMapping model) { using var conn = new MySqlConnection(_connStr); conn.Open(); var sql = $@" DELETE FROM SupplierMappings WHERE SupplierId = @{nameof(SupplierMapping.SupplierId)} AND AccountId = @{nameof(SupplierMapping.AccountId)}; "; return(conn.Execute(sql, model) == 1); }
public bool Exist(SupplierMapping model) { using var conn = new MySqlConnection(_connStr); conn.Open(); var sql = $@" SELECT COUNT(1) FROM SupplierMappings WHERE SupplierId = @{nameof(SupplierMapping.SupplierId)} AND AccountId = @{nameof(SupplierMapping.AccountId)}; "; return(conn.ExecuteScalar <bool>(sql, model)); }
public bool Insert(SupplierMapping model) { //Do not insert existing mapping, it throws exceptions. if (Exist(model)) { return(false); } using var conn = new MySqlConnection(_connStr); conn.Open(); var sql = $@" INSERT INTO SupplierMappings(SupplierId, AccountId) VALUES (@{nameof(SupplierMapping.SupplierId)}, @{nameof(SupplierMapping.AccountId)}); "; return(conn.Execute(sql, model) == 1); }
public SupplierService(ISupplierRepository repo, IMapper mapper) { _supplierRepository = repo; supplierMapping = new SupplierMapping(); }