public Business AddEmployeeToBusiness(EmployeeRegisterToBusiness empRegToBusn) { Business business = _db.Query <Business>(@"SELECT * FROM businesses WHERE pin = @Pin", empRegToBusn).FirstOrDefault(); if (business == null) { return(null); } int success = _db.Execute(@"INSERT INTO businessEmployees (employeeId, businessId) VALUES (@employeeId, @businessId);", new { employeeId = empRegToBusn.UserId, businessId = business.Id }); if (success != 1) { return(null); } _db.Execute(@"UPDATE users SET isEmployee = 1 WHERE id = @UserId;", empRegToBusn); business.Pin = null; return(business); }
public Business EnrollInBusiness([FromBody] EmployeeRegisterToBusiness creds) { if (!ModelState.IsValid) { throw new Exception("Invalid information."); } return(_repo.AddEmployeeToBusiness(creds)); }